Session cookies are working fine in Chrome and Firefox, but with IE9 and AJAX requests, I lose all session cookies.
Direct request to view
public class AddressController : Controller
{
[MvcSiteMapNode(Title = "Addresses", ParentKey = "MyAccount", Key = "Addresses")]
public ActionResult Index()
{
....
var memberId = GetKeyValues.GetMemberId(); // This works perfect.
...
}
Ajax call
$.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();
}
}
}
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.
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}
but 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+ ....
Why?
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.
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.
No Session Cookies on Internet Explorer 9 AJAX requests
Cookie blocked/not saved in IFRAME in Internet Explorer
Some ideas:
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).
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.
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() ...
Have you thought of using sessionStorage? check it out for firefox
https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
for all other browsers:
https://code.google.com/p/sessionstorage/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With