开发者

ASP.NET Website HttpContext.Items is empty at random in HTTPHANDLER

I am having trouble accessing the HttpContext.Items[typeof(UserProfile)] object sometimes when the Http Handler is called, where UserProfile is the object stored in the session cookie via forms authentication.

It works 100% of the time when I open the browser on the same machine it is being deployed or debugging in visual studio, but it fails out ran开发者_C百科domly when I test from a remote computer. I put in some tracing, and basically the HttpContext.Items[typeof(UserProfile)] is null even when the Session Cookie was passed successfully, according to fiddler.

I have tried implementing IReadOnlySessionState in the HTTPHandler but it still does not work. I do realise that sometimes, after like 3 minutes or more of logging in, it works 100% of the time after that.

Any ideas on why this might be happening and solution?

Thx


Session State, Forms Authentication andHttpContext.Items all are unrelated - so not sure why are you mixing them up. The forms authentication has its own cookie separate from session cookie and its life time can be different. You can have session state irrespective of user has been authenticated or not. I am also not certain how you are storing UseProfile object in the session cookie - advise to put some code.

HttpContext.Items is property bag associated with the each HttpRequest - note that this collection is available only for the request life time and there is no built-in mechanism to persist the collection. So its unlikely that you are going to get your UserProfile object in this collection unless you are putting it there for each request in some module or global.asax. You need to explain what exactly you are doing perhaps with code samples!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜