Alex Rivera | Logout

ASP.Net: If I have the Session ID, Can I get the Session object?

Asked 2008-09-11T00:52:25.053
14

This question is related to this one, though I think I was a little too long-winded there to really get a good answer. I'll keep this brief.

I'm working on a web handler (ashx) that accepts a form post from an aspx page. When the handler receives this form post, in order to do what it needs to do, it needs to know the user who is logged in (User.Identity.Name), but I can't rely on cookies being sent by the browser.

I know I can get the Session.SessionID and place it in a hidden form field, but once my handler receives the form post, how can I use that SessionID to figure out the logged-in user's identity?

I'm using the StateServer mode for session state.

Edit
Report

1 Answer

0

In an HttpHandler or HttpModule implementation, you cannot always access session from the BeginRequest event. There is another event you can handle, called OnAcquireRequestState. If you write your code in that event, then HttpContext.Current.Session will not be null.

answered 2008-09-11T01:38:53.337

Your Answer