In MVC, how can I properly handle a page time out in an AJAX Form. Currently when submitting an AJAX Form, the DOM of the AJAX form is replaced by the login page content. I would like to redirect the entire page to the Login page.
I have an ASP.Net MVC application with a Partial Form inside an Ajax form (AJAX.BeginForm). The application is using Windows Form Authentication. Normally when the website times-out, you are correctly redirected to the Login page. However when the AJAX Form submits and the website has timed-out, MVC returns the Login page as the content of the AJAX Form. The Controller action method is never reached. I have tried JQuery.load with the same result.
Controller
public ActionResult Index()
{
ViewData["Now"] = DateTime.Now.ToString("HH:mm:ss");
return View("Index");
}
public ActionResult AjaxTimeout()
{
ViewData["Now"] = DateTime.Now.ToString("HH:mm:ss");
return PartialView("AjaxTimeout");
}
Timeout.aspx
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<html>
<head>
<script src="/Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>
</head>
<body>
Parent page:
<div id="ajaxtimeout" style="height:300px; width:300px;">
<%= Html.Partial("AjaxTimeout") %>
</div>
</body>
</html>
AjaxTimeout.ascx
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<% using (Ajax.BeginForm("AjaxTimeout", new AjaxOptions { UpdateTargetId = "ajaxtimeout"})) { %>
Return Time: <%= ViewData["Now"] %>
<input type="submit" value="Submit" />
<% } %>