Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 正在ASP.NET MVC中清除会话_Asp.net Mvc_Filter_Onactionexecuting - Fatal编程技术网

Asp.net mvc 正在ASP.NET MVC中清除会话

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

会话启动调用和ActionFilterAttribute中的OnActionExecuting之间的会话会发生什么情况

出于某种原因,当我设置如下内容时:

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开始