MVC 登出後可以在Controller加上Filter進行導頁,但是ajax沒辦法。所以要對ajax特別處理。
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
var jsonResult = new JsonResult();
jsonResult.Data = (new { code = "F", message = "Session TimeOut", ForceRedirectURL = "/Login/FailIdVerified" });
if (filterContext.HttpContext.Request.HttpMethod == "GET")
jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
filterContext.Result = jsonResult;
}
else
{
filterContext.Result = new RedirectResult("~/Login/FailIdVerified");
}
ajax增加:
if (response.ForceRedirectURL !== undefined) {
location.href = response.ForceRedirectURL;
}