简体   繁体   English

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

[英]How to clear session on Custom HandleError Attribute in MVC?

I am creating my own custom HandleError attribute on MVC. 我在MVC上创建自己的自定义HandleError属性。

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

But it seems that I cannot use the Session to remove specific session on my website. 但是似乎我无法使用该会话删除我网站上的特定会话。 Is this possible? 这可能吗? Or do I need to clear my session on Global.asax file: 还是我需要清除有关Global.asax文件的会话:

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

You can clear use HttpContext.Current object HttpContext.Current.Session.Remove("Check"); 您可以清除使用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");
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM