get session ID in ASP.Net

后端 未结 6 1624
滥情空心
滥情空心 2021-02-02 07:31

how can I get IDs of all current sessions?

6条回答
  •  醉酒成梦
    2021-02-02 08:16

    To get the session id, do this:

    // In a user control or page
    string sessionId = this.Session.SessionID; 
    
    // In a normal class, running in a asp.net app.
    string sessionId = System.Web.HttpContext.Current.Session.SessionID; 
    

    You should not need to:

    • Make any data table or loop anything
    • Use SQL server for session state
    • Handle Session_Start or Session_End

    In a cookieless scenario, the session id is created when you access the Session object for the first time. This shouldn't matter much, because the moment you access the SessionID property, the session object is accessed.

    For more info, look into this:

    http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.sessionid.aspx

    Note: The msdn examples have been written by monkeys.

提交回复
热议问题