开发者

Clear session in logout.ashx

开发者 https://www.devze.com 2023-03-21 19:19 出处:网络
I have an ashx handler and want to clear the session on request. I am getting object not set to instance of object on the Session.Abondon() line. I am trying to logout a user.

I have an ashx handler and want to clear the session on request. I am getting object not set to instance of object on the Session.Abondon() line. I am trying to logout a user.

 public void ProcessRequest开发者_运维知识库 (HttpContext context) {
    //context.Response.ContentType = "text/plain";
    //context.Response.Write("Hello World");
    FormsAuthentication.SignOut();
    context.Session.Abandon();
    context.Response.Redirect("/login.aspx");        
 } 

Am I doing something wrong?


Did you forget to implement IReadOnlySessionState or IRequiresSessionState in your handler by chance? If so you would not have access to the Session and get this error. These are marker interfaces whose sole purpose it is to give you access to the Session.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号