close

一.由IIS產生Session並給予一組24字元的SessionID

二.在需要回傳資料給伺服器時由瀏覽器將SessionID附加在HTTP訊息標頭中傳回給IIS做為身份辨識,伺服器處理完資料後依照SessionID回傳給個別的Client端

三.Session在Web.config的常用設定
1.在<System.Web>標籤內
< sessionState
mode="Off|InProc|StateServer|SQLServer"
cookieless="true|false"
timeout="number of minutes"
stateConnectionString="tcpip=server:port"
stateNetworkTimeout="number of seconds" 
sqlConnectionString="sql connection string"
sqlCommandTimeout ="number of seconds"
/>

ex.

<sessionState 
mode="StateServer" 
stateConnectionString="tcpip=127.0.0.1:42424" 
stateNetworkTimeout="10" 
cookieless="false" 
timeout="20" 
/>

2.常用屬性介紹

必須有的屬性
(A)mode : 設定Session的狀態為關閉或儲存方式,其參數如下...
    (a) OFF: 不使用Session.
    (b) InProc: 與ASP的Session儲存方式相同,與IIS的狀態有關係.(跟隨IIS程序執行而存在,若IIS關閉或重新啟動則Session消失)
    (c) StateServer: 儲存在獨立的狀態下,與IIS的狀態無關係.
    (d) SQLServer: 儲存在SQL資料庫裡,與IIS的狀態無關係.

可選擇的屬性
(A) cookieless 
    (a) True : 使用Cookieless模式,不使用Client端瀏覽器Cookie改為透過URL傳送SessionID.
                     ex. ttp://localhost/MyTestApplication/(tgdde33errret225f1gdfd) /default.aspx
                     粗體字部分為IIS自動加上(括號內為SessionID),不影響之前的連結.
    (b) False : 使用Cookie模式,預設值),Client端瀏覽器Cookie須開啟(Session在Client端是以Cookie的型態存在)。
(B) timeout : 有效時間(分鐘數),預設值為20分鐘.
(C) stateConnectionString : 若mode為StateServer必須設定此屬性,例如:"tcpip=127.0.0.1:42424”。
(D) stateNetworkTimeout : 若mode為StateServer必須設定此屬性,設定StateServer模式儲存Session的時間,預設值10秒.
(E) sqlConnectionString : 若mode為SQLServer必須設定此屬性,例如"data source=localhost;Integrated Security=SSPI;Initial   Catalog=northwind"。
(F) sqlCommandTimeout : 若mode為SQLServer必須設定此屬性,設定SQLServer模式儲存Session的時間,預設值10秒.

arrow
arrow
    文章標籤
    c# asp.net
    全站熱搜

    Frank 發表在 痞客邦 留言(0) 人氣()