开发者

Asp.Net Session is null in ashx file

开发者 https://www.devze.com 2022-12-18 14:13 出处:网络
I am trying to access开发者_运维百科 the Session variable in Asp.Net ashx handler as shown below.

I am trying to access开发者_运维百科 the Session variable in Asp.Net ashx handler as shown below.

public void ProcessRequest (HttpContext context) {
        context.Session["VariableName"] = Id;
    }

But the context.Session is always Null inside the above method. How do I access Session objects in ashx file?


You have to "implement" either IRequiresSessionState or IReadOnlySessionState, with former providing full access to session, and the latter providing read-only access.

I'm quoting "implement" here because these two are so-called "marker interfaces", which means they have no members.


In VB, implement the interfaces mentioned by Anton (IRequiresSessionState or IReadOnlySessionState) like this:

Public Class MyAshxFile

    Implements System.Web.IHttpHandler
    Implements System.Web.SessionState.IRequiresSessionState ''need this for session variables
    Implements System.Web.SessionState.IReadOnlySessionState ''need this for session variables
0

精彩评论

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

关注公众号