Do not redirect controller actions that are invoked through AJAX. You can use JSON:
public ActionResult Foo() { var url = Url.Action("Bar", "Baz"); return Json(new { location = url }, JsonRequestBehavior.AllowGet); }
and now in your AJAX callback:
success: function(result) { window.location.href = result.location; }
Obviously, if you intend to always redirect from the client side after an AJAX request, this completely destroys any benefits from AJAX. Just call the controller action using the standard link => in this case it makes no sense to use AJAX.
UPDATE:
It looks like you are trying to intercept a redirect to the LogOn page when the authentication cookie expired. Phil Haack wrote about this on his blog: http://haacked.com/archive/2011/10/04/prevent-forms-authentication-login-page-redirect-when-you-donrsquot-want.aspx
In this article, it illustrates how you can prevent the Authentication Forms module from automatically redirecting you to the LogOn page, and instead send a 401 status code, which can be intercepted by your AJAX request and redirect to the client.
source share