2014-03-26 71 views
0

如何在我的自定義授權過濾器中使用Session["userName"]在自定義授權過濾器中訪問會話

void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext) 
{    
    string userName = Session["userName"]; // Shows error "The name 'Session' does not exist in the current context    

    base.OnAuthorization(filterContext); 
} 

回答

4

Session的詞典可用槽:

void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext) 
{    
    string userName = filterContext.HttpContext.Session["userName"];    

    base.OnAuthorization(filterContext); 
}