简体   繁体   中英

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:

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

Then, i have another Handler, Send.ashx and i want to get the object saved in 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.

I think what they mean is in Authentication.ashx:

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

And in 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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