我想创建一个搜索会话数据的助手,最好是这样的:
public static bool CheckForModerator(this HtmlHelper htmlHelper)
{
return Session["isAdmin"];
}
但我无法访问Session []数据。我尝试查看htmlHelper
,但我也找不到Session。我需要做什么才能访问会话数据?
答案 0 :(得分:8)
using System.Web;
然后
HttpContext context = HttpContext.Current;
return context.Session["isAdmin"];
答案 1 :(得分:3)
首选(bool)htmlHelper.ViewContext.HttpContext.Session["IsAdmin"]
答案 2 :(得分:2)
尝试从System.Web.HttpContext.Current.Session