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

后端 未结 4 1504
天涯浪人
天涯浪人 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:25

    John,

    I'm assuming you're using an ashx handler for the handler. If so, be sure to derive from IRequiresSessionState for example:

    public class Images : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    { }
    

    If you're not using an ashx can you describe what you mean by dynamic image page?

    Josh

    0 讨论(0)
  • 2020-12-10 13:32

    yes you are right This happens because the object dependancy might conficts in case of other page transferance parallel which may break down the firewall between sessions

    0 讨论(0)
  • 2020-12-10 13:35

    Session has nothing to do with being logged in or not.

    What event are you overriding when you want access to the session? Session isn't available until AcquireRequestState has been fired.

    For more information, see: http://msdn.microsoft.com/en-us/library/9ysfzy8h.aspx

    0 讨论(0)
  • 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! :)

    0 讨论(0)
提交回复
热议问题