.Net 登出後 ajax 的處理

GorgoasTW
2 min readFeb 14, 2018

--

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;
}

--

--

GorgoasTW
GorgoasTW

Written by GorgoasTW

iOS Developer/.NET Developer/Father

No responses yet