如何清除MVC中有关Custom HandleError属性的会话?

时间:2019-04-22 03:43:18

标签: c# asp.net asp.net-mvc

我正在MVC上创建自己的自定义HandleError属性。

public class MVCError : HandleErrorAttribute
{
    public override void OnException(ExceptionContext filterContext)
    {
         //Supposed to remove session here
    }
}

但是,似乎无法使用该会话来删除我网站上的特定会话。这可能吗?还是我需要清除Global.asax文件上的会话:

    protected void Application_Error()
    {
        Session.Remove("Check");
        Debug.WriteLine("An error has occurred.");
    }

1 个答案:

答案 0 :(得分:1)

您可以清除使用HttpContext.Current对象HttpContext.Current.Session.Remove("Check");

public class MVCError : HandleErrorAttribute
    {
        public override void OnException(ExceptionContext filterContext)
        {
             //Supposed to remove session here
             HttpContext.Current.Session.Remove("Check");
        }
    }
相关问题