Skip to main content

Posts

Showing posts with the label Redirect user to login page if session null in MVC 5 Razor syntax

Redirect user to login page if session null in MVC 5 Razor syntax

For Example using MVC 5 Razor:   @{      //get user session.      var session = UserManager .Session();      if (session == null )      {         Response.Redirect ( "~/Account/LogOff" );      }   }                                           OR We can also use the custom action filter to achieve this functionality. i.e. For Example : // Override onAuthentication filter to achieve this functionality . //and also get user session to check is null value. protected override void OnAuthentication ( AuthenticationContext filterContext) {       session = UserManager .Session();...