How can I get the value of a session variable inside a static method?

前端 未结 4 964
夕颜
夕颜 2020-11-30 02:50

I am using ASP.NET page methods with jQuery.... How do I get the value of a session variable inside a static method in C#?

protected void Page_Load(object se         


        
4条回答
  •  时光说笑
    2020-11-30 03:30

    If you haven't changed thread, you can use HttpContext.Current.Session, as indicated by jwwishart.

    HttpContext.Current returns the context associated with the thread. Obviously this means you can't use it if you've started a new thread, for example. You may also need to consider thread agility - ASP.NET requests don't always execute on the same thread for the whole of the request. I believe that the context is propagated appropriately, but it's something to bear in mind.

提交回复
热议问题