get session ID in ASP.Net

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

how can I get IDs of all current sessions?

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 08:27

    You can use Global.asax file and set the Session at Session_Start event. See below

    in Global.asax file you can do something like this:

    protected void Session_Start(object sender, EventArgs e)
    {
        Session["sid"] = Session.SessionID;
        Session["sid"] = "Test";
    } 
    

    Then in your WebForm you can get the Session ID and Value like below

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("Session ID is:" + Session.SessionID.ToString()+ "
    "); Response.Write("Session value is:" + Session["sid"].ToString()); }

    For details, see http://www.dotnetcurry.com/ShowArticle.aspx?ID=126

提交回复
热议问题