开发者

Session is null in PreRequestHandlerExecute

In my ASP.NET 4.0 application, I've got an event handler for PreRequestHandlerExecute in global.asax.cs.

I want to access data in the Session. Most times, the session is 开发者_开发技巧defined, but sometimes it is null. Can somebody explain me when it is initialized and when it is not?


The session is not loaded for every type of request by default. If the request is for a content file (like an image or stylesheet), then the session is not loaded. This done in order to reduce the overhead of processing a request. If working in the Generic Handler (.ashx) and you want access to the session, then have the handler implement IRequiresSessionState.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜