为什么我在IE 9中丢失了关于Ajax请求的cookie和会话 [英] Why I am losing cookies and session on Ajax requests in IE 9

查看:122
本文介绍了为什么我在IE 9中丢失了关于Ajax请求的cookie和会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

会话cookie在Chrome和Firefox中可以正常工作,但是在IE9和AJAX请求下,我丢失了所有会话cookie.

Session cookies are working fine in Chrome and Firefox, but with IE9 and AJAX requests, I lose all session cookies.

直接请求查看

  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链接

From AJAX call I lost cookies values only IE9. I tried P3P override still did not work from this post P3P link

有人有类似的问题吗?请让我知道如何解决此问题.我已经花了一天的时间.

Has anyone had a similar issue? Please let me know how to resolve this. I spent already a day on this.

我刚刚在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}

I just traced in Fiddler IE is not sending Header data it is just sending "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+ ....

为什么?

推荐答案

这些只是一些想法,可能会有所帮助(并且您现在可能已经阅读或尝试了这些想法).似乎没有灵丹妙药.

These are just some ideas, which may help (and you've probably read or tried these by now). There doesn't seem to be a silver bullet.

其他一些问题也有类似的问题,这些问题似乎并不完全是您的(特别是因为您尝试过P3P).互联网上的帖子也很多,都围绕着同样的几个问题.

Some other questions had similar problems, that don't seem to be exactly yours (especially since you tried P3P). Also lots of posts in general on the internet, all around the same few issues.

在Internet Explorer 9 AJAX请求上没有会话Cookie

Cookie已被阻止/未保存在IFRAME中在Internet Explorer中

一些想法:

  • 一个答案的网址中存在下划线问题.你没有 那,但是你能尝试一个没有random参数的干净的吗?只是 如果不喜欢的话.
  • 许多有关执行此操作的帖子 在iframe中.如果您没有iframe,则不是 问题.
  • P3P,您说您尝试过;我看到一个评论,标题 必须针对每个请求进行设置,而不仅仅是寻找 会话/Cookie.
  • 跨域/CORS问题?看起来不像 与您的root相对URL.
  • 在另一台计算机上尝试IE9?愚蠢的, 但这可能是您浏览器上的一些晦涩的设置;区域等.
  • 提琴手是否在您网站上浏览的常规页面上显示会话ID? (只是为了确保它不在整个站点范围内,而不仅仅是在这个Ajax调用中).

  • One answer had problems with underscore in the url. You don't have that, but can you try a clean one without the random parameter? Just in case it doesn't like that.
  • Lots of posts about trouble doing this from within an iframe. If you don't have an iframe, this isn't the problem.
  • P3P, you said you tried; I saw one comment that the header has to be set on every request, not just the ones looking for session/cookies.
  • Cross-domain / CORS problem? Doesn't look like it with your root-relative url.
  • Try an IE9 on another computer? Silly, but maybe it's some obscure setting on your browser; zones, etc.
  • Does fiddler show a session id on a regular page browsed on your site? (just to make sure it's not site-wide vs. just this ajax call).

我通常发布ajax而不是Get(只是有很多数据),然后执行 有会议工作.这也避免了需要清除缓存 随机参数.

I usually Post ajax instead of Get (just had a lot of data), and do have session working. This also avoided needing the cache-busting random parameter.

我使用的是旧的Web表单而不是mvc,并发布到了asmx.在 asmx方法,我需要装饰服务器端方法.

I'm using good old web forms instead of mvc, and posting to asmx. On the asmx method, I need to decorate the server-side method.

// 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() ...

这篇关于为什么我在IE 9中丢失了关于Ajax请求的cookie和会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆