我目前增加一個動作過濾器來處理會話超時在我們的網站:會話超時後,什麼設置System.Security.Principal.Identity.IsAuthenticated?
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class SsoExpireFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if(!(filterContext.Controller.GetType() == typeof(HomeController)
&& filterContext.ActionDescriptor.ActionName == MVC.Home.ActionNames.Index))
{
if(filterContext.ActionDescriptor.ActionName != MVC.Home.ActionNames.TimeoutRedirect.ToLower())
{
if (!Thread.CurrentPrincipal.Identity.IsAuthenticated)
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
filterContext.Result = new JsonResult { Data = "_Logon_" };
else
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary
{
{"Controller", "Home"},
{"Action", "TimeoutRedirect"}
});
}
}
}
base.OnActionExecuting(filterContext);
}
}
我期待在Principal.Identity的IsAuthenticated標誌是假的以下超時,但它是真正的剩餘,當它在被擊中動作過濾器。 (我知道會話已經超時了,因爲我在Global.asax的Session_End中放了一個斷點,這首先被觸發)。
我們網站的身份驗證是由公司標準的「單一登錄」DLL處理的,所以我猜測這是設置一個單獨的身份驗證超時,這聽起來可能嗎?
任何幫助表示讚賞。
我可能是錯的,但我認爲這篇文章可能會派上用場 http://www.hanselman.com/blog/SystemThreadingThreadCurrentPrincipalVsSystemWebHttpContextCurrentUserOrWhyFormsAuthenticationCanBeSubtle.aspx 或第 http://stackoverflow.com/questions/6810808/thread -currentprincipal-identity-vs-httpcontext-user-identity –