Asp.net System.Web.HttpContext.Current.Session null in global.asax

后端 未结 4 1513
天涯浪人
天涯浪人 2020-12-10 13:06

I have a custom security principal object which I set in the global.asax for the current thread and all is well, no problems normally.

However, I\'m just adding a dy

4条回答
  •  甜味超标
    2020-12-10 13:40

    in Global.asax.cs Session_Start() and Session_End() you need to use "this.Session" !! The reason for this is that HttpContext is only available when there is a request that is being processed. That is why you are getting a NULL on HttpContext.Current.Session!

    From Microsoft website: "HttpContext Class: Encapsulates all HTTP-specific information about an individual HTTP request."

    But don't feel bad ... i fell for this one too! :)

提交回复
热议问题