Asp.net mvc 正在ASP.NET MVC中清除会话
会话启动调用和ActionFilterAttribute中的OnActionExecuting之间的会话会发生什么情况 出于某种原因,当我设置如下内容时:Asp.net mvc 正在ASP.NET MVC中清除会话,asp.net-mvc,filter,onactionexecuting,Asp.net Mvc,Filter,Onactionexecuting,会话启动调用和ActionFilterAttribute中的OnActionExecuting之间的会话会发生什么情况 出于某种原因,当我设置如下内容时: protected void Session_Start(object sender, EventArgs e) { Session["GoToBuyPage"] = true; } protected void Session_Start(object sender, EventArgs e) { Session["GoT
protected void Session_Start(object sender, EventArgs e)
{
Session["GoToBuyPage"] = true;
}
protected void Session_Start(object sender, EventArgs e)
{
Session["GoToBuyPage"] = true;
}
并尝试在ActionFilterAttribute中访问它:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
bool goToPage = (bool)Session["GoToBuyPage"];
它总是空的。知道为什么吗?没有
会话
属性的操作过滤器属性
。所以我甚至不知道你的代码是如何编译的。以下内容对我来说非常有用:
操作筛选器:
public class FooAttribute: ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
bool goToPage = (bool)filterContext.HttpContext.Session["GoToBuyPage"];
filterContext.Result = new ContentResult
{
Content = goToPage.ToString()
};
}
}
控制器:
public class HomeController : Controller
{
[Foo]
public ActionResult Index()
{
return View();
}
}
会话\u开始
: