会话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没有发送它只发送"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+ ....
为什么?
答案 0 :(得分:5)
这些只是一些想法,可能会有所帮助(你现在可能已阅读或试过这些想法)。似乎没有银弹。
其他一些问题也存在类似的问题,这些问题似乎并非完全属于您(特别是因为您尝试过P3P)。在互联网上也有很多帖子,所有这些都围绕着同样的问题。
No Session Cookies on Internet Explorer 9 AJAX requests
Cookie blocked/not saved in IFRAME in Internet Explorer
一些想法:
fiddler是否会在您网站上浏览的常规网页上显示会话ID? (只是为了确保它不是站点范围而不是这个ajax调用)。
我通常发布ajax而不是Get(只是拥有大量数据),并且做到了 会议工作。这也避免了需要缓存破坏 随机参数。
我使用的是旧的Web表单而不是mvc,并发布到asmx。上 asmx方法,我需要修饰服务器端方法。
// ScriptService and ScriptMethod are required for the jquery.ajax() call. They weren't required for jquery.post(). WebMethod needed for session.
[WebMethod(EnableSession = true)]
[ScriptMethod]
public string DoSomething() ...
答案 1 :(得分:2)
您是否考虑过使用sessionStorage?检查一下firefox
https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
适用于所有其他浏览器: