因此,我得到了一個返回JSON結果的ajax方法,但方法的一部分是檢查會話是否有效。如何在超時時重定向Ajax Method會話
所以如果用戶刷新一個頁面,那麼會調用ajax方法,在會話過期的時候會拋出異常,現在該方法想要返回一個JSON結果,但是我想將它們重定向到登錄頁。
我該怎麼做?
public JsonResult GetClients()
{
var usertoken = new UserToken(this.User.Identity.Name);
if (usertoken.AccountId != null)
{
return new JsonResult() {Data = model, JsonRequestBehavior = JsonRequestBehavior.AllowGet};
}
else
{
//Redirect Here
}
.js文件中查見這個問題:http://stackoverflow.com/questions/5102964/how-to-redirect-to-new-page -after-jQuery的Ajax的通話中MVC-如果會話超時 –