我从一个自定义的授权属性所采取的代码,并提出了这一点:自定义授权属性并不总是工作
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