简体   繁体   English

在ashx处理程序上的Session中保存对象,并在另一个ashx处理程序中获取对象。 怎么样?

[英]Save object in Session on a ashx handler and get the object in another ashx handler. How?

I have two handlers. 我有两个处理程序。

In Authentication.ashx Handler i save a object on session like this: 在Authentication.ashx处理程序中,我将一个对象保存在会话中,如下所示:

HttpContext.Current.Session["ConnectionUserSession"] = userCache;

Then, i have another Handler, Send.ashx and i want to get the object saved in Authentication.ashx. 然后,我有另一个处理程序Send.ashx,我想将对象保存在Authentication.ashx中。

How i do that? 我该怎么做? My code to get the object is: 我获取对象的代码是:

UserCache userCache = (UserCache) HttpContext.Current.Session["ConnectionUserSession"];

The problem: userCache is allways null, and i have IRequiresSessionState implemented on both handlers. 问题:userCache始终为null,并且我在两个处理程序上都实现了IRequiresSessionState。

I think what they mean is in Authentication.ashx: 我认为它们的意思是Authentication.ashx:

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

And in Send.ashx, 在Send.ashx中

public void ProcessRequest (HttpContext context) {
    UserCache userCache = (UserCache) context.Session["ConnectionUserSession"];
}

Either the line 要么线

HttpContext.Current.Session["ConnectionUserSession"] = userCache;

is not executed, or the string keys used for saving and retrieval are different, or you have a call to 未执行,或者用于保存和检索的字符串键不同,或者您有一个调用

Session.Abandon();

between these two handlers. 在这两个处理程序之间。

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

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