c# how to set up and use session state from preinit

后端 未结 3 1485
温柔的废话
温柔的废话 2020-12-20 09:56

OK so to set and read variables from the current session

String Myvar =(string) System.Web.HttpContext.Current.Session[“MyVariable”]

To set

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-20 10:02

    You can access the session by implementing IRequiresSessionState interface in your class.

    This is a flag interface, so you dont need to implement any extra code.

    When you implement this asp.net will know that you want to access the session.

    public partial class YOUR_ASPX: System.Web.UI.Page , IRequiresSessionState
    {
    
    ... your code
    
    }
    

提交回复
热议问题