SimonGoldstone
SimonGoldstone

Reputation: 5216

MVC FormsAuthentication time out - AJAX considerations

Hope you can help. In my ASP.net MVC3 app, all my controllers descend from a customized controller I have created.

Upon FormsAuthentication time out, my app correctly redirects users to the login page if they attempt to access any page (standard functionality).

However, for Ajax.ActionLink and Ajax.BeginForm calls, they just return nothing, which confuses users if the browser is left open for more than 20 minutes and then they try to access an Ajax link.

Is there any code I can put in to my base controller that will work generically so that when it detects an inbound Ajax call and we have timed-out, it will redirect users to my login page as expected?

I don't mind if it doesn't return to the original page afterwards - happy for it to just go to the Home Index page.

Thanks in advance for any help you can provide.

Simon.

Upvotes: 0

Views: 2602

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038880

You may take a look at the following blog post which illustrates a nice way to prevent the FormsAuthentication module from redirecting to the logon page in case of an AJAX request and simply send a 401 status code to the client so that it can act accordingly.

Upvotes: 4

Related Questions