views:

1197

answers:

1

I'm using ASP.Net MVC beta 1 and I'm using the asp.net membership provider with the standard authentication controller to restrict access to my site.

I'm using ajax functionality to provide e.g. editing of values by loading partial views into a div with either jQuery $.get/$.ajax or with the Ajax.Actionlink MVC helper. This all works fine most of the time.

My problem comes once the login times out and you click on one of the ajax edit links - the ajax call returns the login page which is put into the div normally used for the edit form.

I want to find a way to redirect the whole page to the login form, when the authentication has timed out and an ajax link is clicked.

One way I can think of is looking at the html returned from the ajax call in the response callback and searching for the 'login' text or form field and doing a redirect from there - but this doesn't feel very clean - is there a better way?

+2  A: 

This might help some:

http://stackoverflow.com/questions/35322/bypass-forms-authentication-auto-redirect-to-login-how-to

From the above answer it looks like http 403 isn't intercepted by Forms Authentication, so you can roll your own ActionFilter that returns an http 403 response if its an Ajax Request and Authorization failed.

On the client side, you could then check the response code for 403, and redirect to the appropriate login url.

There are probably other ways to do this as well!

eyston