Asp.Net Session 在 ashx 文件中为空

Asp.Net Session 在 ashx 文件中为空

问题描述:

我正在尝试访问 Asp.Net ashx 处理程序中的 Session 变量,如下所示.

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;
    }

但是 context.Session 在上述方法中总是 Null.如何访问 ashx 文件中的 Session 对象?

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

您必须实施"任一IRequiresSessionStateIReadOnlySessionState,前者提供对会话的完全访问权限,后者提供只读访问权限.

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.