是否爲每個頁面請求創建會話?即使我們沒有任何表單身份驗證啓用或在應用程序中創建的任何會話對象?何時在任何asp.net web應用程序中創建會話?
回答
SessionID屬性是用來唯一標識與服務器上的會話數據的瀏覽器。 SessionID值由ASP.NET隨機生成,並存儲在瀏覽器中的非到期會話cookie中。 SessionID值隨後會在每個請求發送到ASP.NET應用程序的Cookie中。
因此,當瀏覽器請求需要會話狀態的資源時,如果會話狀態模塊無法找到現有會話ID(無論是在ASP.NET會話cookie中,還是在無Cookie會話的情況下),然後創建一個新的會話ID並返回到會話ID Cookie中。
會話ID用於檢索一組會話狀態值(通常稱爲「會話變量」)。只要會話存在,存儲在這種「變量」中的數據將保持可用。如果會話超時,或者AppDomain重新啓動,或者Cookie變得不可用,則會話「變量」將包含空值。使用會話狀態的代碼必須對此有所準備:
糟糕的代碼:
string user = Session["User"];
int length = user.Length; // NullReferenceException if session was expired
更好的代碼:
string user = Session["User"];
if (user == null) {
// Do without the user information
} else {
int length = user.Length; // User information is available
}
會話狀態數據會在所有數據的表現形式,但對於唱歌的用戶全局共享數據。
Declaration For the session :
Session["Key"] = "value";
Session data are stored on the server side.
Session state variables are declared when session times out.
By default time out for session is 20 minutes.
例如:
**If you are using session & you are executing the first session web form & suppose you have navigated your page from web-form 1 to web-form 2.
Then Session output will be the same.
If suppose your o/p for web-form 1 is "2".
Then if you have closed the browser & copy and paste the same URL to another browser.
then you will notice that o/p will be the same Because In your URL session ID is present.
there for it will have the same o/p.
This is very Important to understand about session if you want to use the session in your application.**
ie session data session state data shared across all the web-form but only fr single user.
For every session Unique session ID is generated.
But is you have changed your session then new session ID is generated meaning it is only for single user.
我瞭解,當第一個請求轉到服務器時,爲應用程序創建唯一的SessionID,並且映射爲用戶及其各自會話對象(如果有)的唯一身份。如果對我的理解有任何更正,請告知我。感謝所有迴應。 – Shekar
是的,你是完全正確的,Shekar。但有一點要記住的是,如果你想從一個網頁到另一個網頁的一些數據,那麼這是非常有用的。 –
- 1. ASP.NET Web應用程序會話問題
- 2. ASP.NET:在任何Active Directory中創建用戶的應用程序
- 3. 如何在asp.net web應用程序中創建webshare?
- 4. 如何在VS2012中創建ASP.NET MVC Web應用程序項目
- 5. 如何在asp.net web應用程序中創建日誌文件?
- 6. 如何在.NET v3.5中創建ASP.NET Web窗體應用程序
- 7. 會話不在ASP.NET Web應用程序超時
- 8. 如何在REST Jersey Web應用程序中創建,管理和關聯會話
- 9. 如何在iPhone應用程序中創建和管理會話?
- 10. 如何在phonegap Android應用程序中創建會話
- 11. 如何在JSF應用程序中創建會話?
- 12. 在任何應用程序屏幕上創建cutom對話框
- 13. 如何在Web應用程序中創建實時協調鎖?
- 14. 如何在Web應用程序中使用託管Hibernate會話
- 15. 如何使用sqlite創建asp.net web應用程序
- 16. PHP會話在2 Web應用程序
- 17. 會話超時在Java Web應用程序中不起作用
- 18. 構建後在Web應用程序中保留會話變量
- 19. 在Asp.net Web應用程序項目中創建用戶角色
- 20. 創建Web會話
- 21. Web應用程序會話緩存
- 22. 在Android中創建Web應用程序
- 23. 在web應用程序中創建ListView
- 24. asp.net web應用程序中的Sql服務器會話模式
- 25. 會話標識符在Asp.NET Web應用程序未更新
- 26. 創建asp.net web應用程序後如何執行Nunit
- 27. 如何創建WebJob我的ASP.NET核心Web應用程序
- 28. 如何使用web服務共享Web應用程序會話
- 29. 如何從Web應用程序中找出ASP.NET中的會話大小?
- 30. 會話的Web應用程序
-1:報價是準確的,但你的解釋不匹配報價。 –
瀏覽器建立新連接時。我將編輯... –
不,它與連接無關 –