簡體   English   中英

會話似乎無法正常運行asp.net

[英]Session seem to not work asp.net

我不知道為什么會這樣。 在同一程序中,我正在使用有效的會話。 現在,當用戶不發送cookie(應該很簡單)時,我試圖使我的網站兼容。 我寫

long userId, loginId;
//...
//put data into cookies
HttpContext.Current.Session.Add("userId", userId.ToString());
HttpContext.Current.Session.Add("loginId", loginId.ToString());

我看到他們在這句話中是空的

var cookies = HttpContext.Current.Request.Cookies;
long mUserId;
string u, id;
if (cookies["userId"] == null)
{
    //these are null
    u = (string)HttpContext.Current.Session["userId"];
    id = (string)HttpContext.Current.Session["loginId"];
}

在我設置會話后,在兩種情況下(工作和不工作)

HttpContext.Current.Response.Redirect("someUrl");`

正如CSharpAtl所說,這是設計使然:

但是,在web.config中,如果將會話設置為無cookie,則該方法可以正常運行,但它將向URL添加會話ID。

這是MSDN的相關文章: http : //msdn.microsoft.com/zh-cn/library/aa479314.aspx

如果客戶端不接受cookie,則不能使用SessionState,因為存儲在cookie中的Session狀態有一個鍵,必須用於在回發時檢索Session狀態

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM