我從一個自定義的授權屬性所採取的代碼,並提出了這一點:自定義授權屬性並不總是工作
public class PortalAuthorizeAttribute : AuthorizeAttribute
{
private WebSiteSession m_UserSession;
protected WebSiteSession myUserSession
{
get
{
if (m_UserSession == null)
try { m_UserSession = (WebSiteSession)HttpContext.Current.Session["UserSession"]; }
catch
{
m_UserSession = new WebSiteSession();
HttpContext.Current.Session["UserSession"] = m_UserSession;
}
return m_UserSession;
}
}
public override void OnAuthorization(AuthorizationContext filterContext)
{
if (filterContext.Result is HttpUnauthorizedResult || myUserSession == null || !myUserSession.IsAuthenticated || myUserSession.AdvertiserId == 0)
{
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary
{
{ "client", filterContext.RouteData.Values["client"] },
{ "controller", "Account" },
{ "action", "Login" },
{ "returnUrl", filterContext.HttpContext.Request.RawUrl }
});
}
}
}
我從一個更大的項目中工作,所以我們從更高的命名空間讓我們的會議。如果我註銷或者我沒有授權(重定向到區域登錄頁面),但它似乎如果我閒置(會話超時??)它將仍然按照我的授權行事,但不會有任何憑據附加到會話。所以它仍然認爲我有效登錄,但我不是。我在過濾器檢查中忘記了什麼嗎?該Cookie不再有效,但它仍像用戶仍能訪問該頁面。
感謝
非常感謝,這已經爲我澄清了這個問題。我不知道它緩存了。 – Darren 2012-03-07 17:51:22