自定义授权过滤器中的访问会话
本文关键字:访问 会话 授权 过滤器 自定义 | 更新日期: 2023-09-27 17:53:18
如何在自定义授权过滤器中使用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);
}
Session
字典通过:
void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext)
{
string userName = filterContext.HttpContext.Session["userName"];
base.OnAuthorization(filterContext);
}