Jam*_*123 13 cookies ajax asp.net-mvc jquery asp.net-mvc-4
会话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.
...
}
Run Code Online (Sandbox Code Playgroud)
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
从AJAX调用我丢失的cookie值只有IE9.我试过P3P覆盖仍然没有工作从这篇文章P3P链接
有没有人有类似的问题?请让我知道如何解决这个问题.我已经花了一天时间.
我刚刚在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+ ....
为什么?
这些只是一些想法,这可能有所帮助(你现在可能已阅读或尝试过这些).似乎没有银弹.
其他一些问题有类似的问题,似乎并不完全是你的(特别是因为你尝试过P3P).一般在互联网上也有很多帖子,都围绕着同样的问题.
Internet Explorer 9 AJAX请求中没有会话Cookie
Cookie已阻止/未保存在Internet Explorer的IFRAME中
一些想法:
小提琴手是否在您网站上浏览的常规页面上显示会话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() ...
Run Code Online (Sandbox Code Playgroud)你有没有想过使用sessionStorage?看看火狐浏览器
https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
对于所有其他浏览器:
https://code.google.com/p/sessionstorage/
| 归档时间: |
|
| 查看次数: |
2196 次 |
| 最近记录: |