Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session_OnEnd in Global.asax redirect to controller action MVC ASP.NET

I would like to redirect to an action controller gracefully after session expires. Added Session_OnEnd method in my Global.asax file. See code below:

Global.asax:

public void Session_OnEnd()
{
    //redirect to controller action here
}

At first I had "Response.RedirectToRoute" inside the method but throws an exception and can't work technically.

like image 330
felixgondwe Avatar asked Nov 25 '25 03:11

felixgondwe


1 Answers

You can't do this. Session_End could be fired without an actual HTTP context. The user might have even closed his browser long before this event gets fired so there is nowhere to redirect to. The Request and Response objects are not available.

But you can create custom ActionFilter for handling this issue.

Redirect at Session Timeout in Global.asax in mvc4

Detecting Session expiry on ASP.NET MVC

Detecting Session Timeouts using a ASP.Net MVC Action Filter

like image 87
Mohsen Esmailpour Avatar answered Nov 27 '25 18:11

Mohsen Esmailpour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!