如何得到Sessionid的值


當用戶向一個網站請求第一個頁面時,用戶會話啟動。當第一個頁面被請求時,web服務器將
asp.net_sessionID  cookie添加進用戶的瀏覽器。
可以使用newsession屬性探測新會話的啟動。當新會話啟動時,newsession屬性返回true。
response.write(session.newsession).

每個用戶會被分配一個唯一的會話ID,可以像下面這樣獲取會話ID的值
response.write(session.sessionid)
會話ID確保在所有當前用戶會話中是唯一的。但是,隨着時間的推移會話ID不保證唯一;可能將來的新會話循環使用會話ID
看:

protected void Application_Start(Object sender, EventArgs e)
{
       Hashtable ht = new Hashtable();
       Application["SessionIDs"] = ht;
}

protected void Session_Start(Object sender, EventArgs e)
{
       Hashtable ht = (Hashtable) Application["SessionIDs"];
       ht.Add( Session.SessionID, Session.SessionID );
}

protected void Session_End(Object sender, EventArgs e)
{
       Hashtable ht = (Hashtable) Application["SessionIDs"];
       ht.Remove( Session.SessionID );
}

in order to know if a session is alive we use this method:

public bool IsSessionAlive( string id )
{
       Hashtable ht = (Hashtable) Application["SessionIDs"];
       return ht.ContainsKey( id );
}


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM