簡體   English   中英

Cookie.Path不適用於Internet Explorer

[英]Cookie.Path doesn't work with Internet Explorer

我在登錄時創建了cookie。 cookie范圍被限制為路徑。

    HttpCookie cookie = new HttpCookie(cookieName);
    cookie.Expires = DateTime.Now.AddMinutes(expiryMinutes);
    cookie["username"] = username;
    SetCookieValue(cookie, "username", username);
    SetCookieValue(cookie, "password", password);
    SetCookieValue(cookie, "domain", domain);
    cookie.HttpOnly = true;
    cookie.Secure = true;
    cookie.Path = Request.Url.GetLeftPart(UriPartial.Authority);

問題是,盡管此代碼在Firefox和Chrome中可以完美運行,但在Internet Explorer(和Opera)中卻無法運行。 有問題的行是最后一行-在此處設置cookie.path參數時,IE丟棄(我認為)該cookie。 我已經使用Chrome控制台進行了調試,並使用正確的路徑(例如/ application)成功創建了cookie。

這里可能有什么問題?

由於基礎WinINET InternetGetCookie實現中存在一個模糊的錯誤,如果使用包含文件名的path屬性進行設置,則IE的Document.Сookie將不會返回cookie。

例如,如果頁面像這樣設置自身的cookie:

Set-Cookie: HTTPSet-PathCookie=PASS;path=/check.htm

Cookie將與HTTP請求一起發送,但不會出現在Document.Сookie集合中。

請參閱此博客條目

更改

cookie.Path = Request.Url.GetLeftPart(UriPartial.Authority);

對此

cookie.Path = "/";

我假設您想將Cookie應用於整個域。

暫無
暫無

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

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