I have some AJAX calls that render PartialViewResults via the jQuery.AJAX method. This works great, I get my views rendered exactly the way I want.
The problem arises when I leave the page up for a while and the Forms auth session expires. When I click an action that performs an AJAX request, it shows the login page in my div.
I want it to redirect the WHOLE page to the login page.
With current versions of ASP.NET MVC there is a much easier solution to fix this issue:
Response.SuppressFormsAuthenticationRedirect
.You can apply this in your
Global.asax.cs
:Set it up in the Application_EndRequest() method of the Global.asax
You can check to see if the request is an ajax request and also check if it is sending an HTTP redirect (302) if it is, then we actuall want to send a 401.
Then in your client code, in a globally accessible area:
When I have FormsAuthentication in place, I will include the Login URL in the answer https://stackoverflow.com/a/3431350/1559213 provided by @Chris Kooken