I have an ASP.NET MVC4 application where I am implementing sessionTimeout like:
<configuration>
<system.web>
<sessionState timeout="2"></sessionState>
</system.web>
</configuration>
And in authentication:
<configuration>
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="1" />
</authentication>
</system.web>
</configuration>
After the session has expired (2 mins), I need to redirect to the logon page, but the redirection doesn’t occur.
How can I change the code so that it will redirect?
One way is that
In case of Session Expire, in every action you have to check its session and if it is null then redirect to Login page.
But this is very hectic method
To over come this you need to create your own
ActionFilterAttributewhich will do this, you just need to add this attribute in every action method.Here is the Class which overrides ActionFilterAttribute.
Then in action just add this attribute like so:
This will do you work.