tags:

views:

146

answers:

3

I would like to do redirect to login when current session end and that config must be working at any View and Controller.

///My current code in Global.asax

protected void Session_End(object sender, EventArgs e) {
Session.Abandon(); //GetPath() is getting currently path // eg. http://localhost/mymvcproject Response.Redirect(PATH.GetPath() + "User/LogOn"); }

A: 

I don't think your code can work because Session_End() is more usually invoked when there is NO request made by the browser after a specific duration. Therefore, Response here would correspond to no particular request, and thus, no redirection.

Instead, try to handle Application_Start and check for Session.IsNew property. If it's true, then perform the redirection. (Consider doing that by invoking FormsAuthentication.RedirectToLoginPage() though.)

When checking for IsNew, beware of the situation described here. I guess assigning some dummy session variable during the login process will address that, although I haven't tried myself.

Buu Nguyen
A: 

check the following setting under in your web.config file
then fill the following text in your site.Master
if (Session.IsNewSession) { Response.Redirect(PATH.GetPath() + "User/LogOn"); }

Kaung Sitt Thu
A: 

check the following setting under in your web.config file
then fill the following text in your site.Master
if (Session.IsNewSession) { Response.Redirect(PATH.GetPath() + "User/LogOn"); }

Kaung Sitt Thu