0

How I can redirect to Login.cshtml from session_end of Global.asax on session expiry.

Response.redirect() not working there.

Please comment on it.

  • use RedirectToAction("Actionname", "Controllername"); – Amit Jul 18 '16 at 06:01
  • Possible duplicate of [How to redirect to logon page when session State time out is completed in asp.net mvc](http://stackoverflow.com/questions/13873398/how-to-redirect-to-logon-page-when-session-state-time-out-is-completed-in-asp-ne) – Nikhil Ghuse Jul 18 '16 at 06:09

1 Answers1

0

try this may be you will able to check the session is in process or expire

Check this

Answer is given here

check also

Here is the Class which overrides ActionFilterAttribute.

  public class SessionExpireAttribute : ActionFilterAttribute
   {
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        HttpContext ctx = HttpContext.Current;
        // check  sessions here
        if( HttpContext.Current.Session["username"] == null ) 
        {
           filterContext.Result = new RedirectResult("~/Login/Index");
           return;
        }
        base.OnActionExecuting(filterContext);
    }
  }

Then in action just add this attribute as shown :

  [SessionExpire]
  public ActionResult Index()
  {
    return Index();
   }

Or Just add attribute only one time as :

       [SessionExpire]
       public class LoginController : Controller
       {
         public ActionResult Index()
          {
            return Index();
          }
       }
Community
  • 1
  • 1
Nikhil Ghuse
  • 1,258
  • 14
  • 31