【发布时间】:2015-09-01 08:04:56
【问题描述】:
会话 cookie 在 Chrome 和 Firefox 中运行良好,但对于 IE9 和 AJAX 请求,我会丢失所有会话 cookie。
直接请求查看
public class AddressController : Controller
{
[MvcSiteMapNode(Title = "Addresses", ParentKey = "MyAccount", Key = "Addresses")]
public ActionResult Index()
{
....
var memberId = GetKeyValues.GetMemberId(); // This works perfect.
...
}
Ajax 调用
$.ajax({
url: "/Address/CheckPrimaryAddressGood?t="+ Math.random(),
type: "Get",
success: function(data) {
...
public class AddressController : Controller
{
public ActionResult CheckPrimaryAddressGood()
{
...
var memberId = GetKeyValues.GetMemberId();
...
}
}
public static class GetKeyValues
{
public static string GetMemberId()
{
if (HttpContext.Current.Session[keyCookie] != null)
{
memberId = GetMemberIdFromSession();
}
else if (HttpContext.Current.Request.Cookies["token"] != null)
{
memberId = GetMemberIdFromCookie();
}
}
}
从 AJAX 调用中,我只丢失了 IE9 的 cookie 值。我尝试了 P3P 覆盖仍然无法从这篇文章P3P link
有人遇到过类似的问题吗?请让我知道如何解决这个问题。我已经花了一天的时间。
编辑
我刚刚在 Fiddler 中跟踪 IE 没有发送 Header 数据它只是发送 "Connection=Keep-Alive&Pragma=no-cache&Accept=*%2f*&Accept-Encoding=gzip%2c+deflate&Accept-Language=en-US&Host=ebiz.company.com%3a28712&User-Agent=Mozilla%2f5.0+(compatible%3b+MSIE+9.0%3b+Windows+NT+6.1%3b+WOW64%3b+Trident%2f5.0)&Origin=http%3a%2f%2febiz.spe.org%3a28712}
但 Chrome:{Connection=keep-alive&Accept=*%2f*&Accept-Encoding=gzip%2c+deflate%2c+sdch&Accept-Language=en-US%2cen%3bq%3d0.8&Cookie=ASP.NET_SessionId%3d2a4tr1ymierclqsfxyfahqbc%3b+__session%3a0.5654769616667181%3ashowwarning%3dtrue%3b+__session%3a0.5654769616667181%3aBadAddressWarning%3dfalse%3b+ ....
为什么?
【问题讨论】:
-
这可能是 IE 中的安全区域的问题。因此,如果您的连接是 http 并且请求是 https,它将使用另一组 Cookie(或多或少是另一个用户上下文)。
-
这里已经有类似的问题了,看看这里:stackoverflow.com/questions/389456/…
标签: jquery ajax asp.net-mvc asp.net-mvc-4 cookies