我一直在为这个问题寻找解决办法,但我没有办法。顺便说一下,我不明白我的问题的原因。
问题是:
我的web应用程序有一个登录页面,并从cookie获取登录用户id。它以前工作过,但5-6天前,由于一些变化,它没有与IE一起工作。现在它不适用于任何浏览器。
我能看到Chrome里的饼干。当使用Internet开发工具查看时,有时会编写但仍不能被IE读取的cookie
我的网络应用程序在Windows 2008 R2 BTW上
设置我的web.config:
<httpCookies domain=".domainname.com" httpOnlyCookies="false" requireSSL="false" />这是我的SetCookie代码
<!-- language: c# -->
string uId = "userID";
DateTime expireDate = DateTime.Now.AddDays(3);
HttpContext.Current.Response.Cookies["cookieName"]["uID"] = uId;
HttpCookie aCookie = new HttpCookie("cookieName");
aCookie.Values["uID"] = uId;
aCookie.Path = "/";
aCookie.Expires = expireDate;
aCookie.HttpOnly = false;
aCookie.Domain = "domainname.com";
aCookie.Name = "cookieName";
HttpContext.Current.Response.Cookies.Add(aCookie);而这个GetCookie代码
<!-- language: c# -->
if (HttpContext.Current.Request.Cookies["cookieName"] != null)
{
System.Collections.Specialized.NameValueCollection UserInfoCookieCollection;
UserInfoCookieCollection = HttpContext.Current.Request.Cookies["cookieName"].Values;
userID = HttpContext.Current.Server.HtmlEncode(UserInfoCookieCollection["uID"]);
}场景是:
试着登录
SetCookie方法触发
SetCookie方法的末尾有两个cookie "cookieName“和"ASP.NET SessionId”
GetCookie方法触发
只有"ASP.NET SessionId“和会话值仍然是相同的
谢谢你的帮助。
发布于 2011-09-23 06:26:09
我的问题解决了。将我的代码更改为
string uId = "userID";
DateTime expireDate = DateTime.Now.AddDays(3);
var httpCookie = HttpContext.Current.Response.Cookies["cookieName"];
if (httpCookie != null)
{
httpCookie["uID"] = uId;
HttpContext.Current.Response.Cookies.Add(httpCookie);
}
else
{
HttpCookie aCookie = new HttpCookie("cookieName");
aCookie.Values["uID"] = uId;
aCookie.Expires = expireDate;
HttpContext.Current.Response.Cookies.Add(aCookie);
}发布于 2014-05-01 06:48:42
这一次把我弄糊涂了。但设法解决了这个问题如下。因此,基本上,将失效设置为初始值的一部分是无效的。在将cookie添加到response对象之后设置它可以工作!

https://stackoverflow.com/questions/7507111
复制相似问题