1- I have an Ajax link that call an action and that action returns a view , that view open in a specific Div (consider it as a menu that update the div with the corresponding view) 2- if session timeout the returned my logon view
so if i click on the link and session is timeout , the log on view open in the div not in the whole page
what i should do so if the session timeout it return logon view in new page in on my div?
An efficient way to handle a session expiry is to create a custom Authorization attribute and return a HTTP 403 response if the session has expired and were dealing with an ajax request.
To create an Ajax aware authorization attribute you can inherit from AuthorizeAttribute and override the HandleUnauthorizedRequest event with a check on the type of request eg. IsAjaxRequest()
Then just decorate your controllers or actions with the AjaxAuthorize attribute just as you normally would with Authorize
Then if you're using jQuery you can handle the 403 response by creating a global ajax error handler.
You can redirect user to login page on Session_Start event in Global