如何在自定义授权过滤器中使用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);
}
答案 0 :(得分:7)
Session
字典可以通过以下方式获得:
void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext)
{
string userName = filterContext.HttpContext.Session["userName"];
base.OnAuthorization(filterContext);
}