7

我想创建一个搜索会话数据的助手,最好是这样的:

public static bool CheckForModerator(this HtmlHelper htmlHelper)
{
    return Session["isAdmin"];
}

但我无法访问 Session[] 数据。我尝试浏览htmlHelper,但我也找不到 Session 那里。为了访问会话数据,我需要做什么?

4

3 回答 3

9
using System.Web;

进而

HttpContext context = HttpContext.Current;
return context.Session["isAdmin"];
于 2013-01-29T17:30:01.157 回答
3

更喜欢(bool)htmlHelper.ViewContext.HttpContext.Session["IsAdmin"]

于 2017-03-10T20:01:09.883 回答
2

尝试从System.Web.HttpContext.Current.Session

于 2013-01-29T17:28:40.653 回答