2
我在我的網站有很多ajax調用是使用mvc3剃鬚刀構建。 問題是,如果在使用ajax進行操作時會話超時後,它不會重定向到登錄頁面。 我正在使用如下所示的屬性來處理會話超時。沒有重定向到登錄頁面時,會話超時與ajax調用
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext ctx = HttpContext.Current;
// check if session is supported
if(ctx.Request.IsAuthenticated)
{
if (ctx.Session != null)
{
// check if a new session id was generated
if (ctx.Session.IsNewSession)
{
// If it says it is a new session, but an existing cookie exists, then it must
// have timed out
string sessionCookie = ctx.Request.Headers["Cookie"];
if (null != sessionCookie)
{
FormsAuthentication.SignOut();
const string loginUrl = @"~/Login/Login";
var rr = new RedirectResult(loginUrl);
filterContext.Result = rr;
}
}
}
}
else
{
ctx.Response.Redirect(@"~/Login/Login");
}
base.OnActionExecuting (filterContext);
}
在問你自己之前搜索與你有關的問題。大多數時候你會得到它們。 – bhuvin 2012-08-01 08:10:51