0

Following is the code for setting the cookie:

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, "AuthenticationToken", DateTime.Now,
                DateTime.Now.AddSeconds(60), false, "");
string encryptedText = FormsAuthentication.Encrypt(ticket);
Response.Cookies.Add(new HttpCookie("AuthenticationToken", encryptedText));

Following is the code for reading the cookie:

string cookie= Request.Cookies["VPAuthenticationToken"].Value;

this code works fine in Firefox and chrome but does not work in IE 11. This works in IE, Chrome and Firefox on local and Dev. In IE 11, while reading the cookie it is throw null reference exception. I have looked at the Request cookies in Chrome and they are being set to a value whereas the request cookie is not being set in IE 11 I have already tried clearing cookies and setting the security to lowest. Also, this code is triggered from a cross domain call, could that be causing this issue?

Prashant
  • 91
  • 1
  • 9
  • also try to add the 'domain' on the cookies – Aristos Feb 18 '20 at 12:24
  • Domain is already present in the request cookies – Prashant Feb 18 '20 at 12:48
  • @Aristos, took me sometime to understand that this could be related to the domain. – Prashant Feb 18 '20 at 15:22
  • Check this answer : https://stackoverflow.com/questions/12506532/session-would-not-retain-values-and-always-return-null/12506833#12506833 – Aristos Feb 18 '20 at 15:26
  • It seems that IE 11 does not like a domain value in the cookie. You could try to leave it empty. You could refer to [this thread](https://stackoverflow.com/questions/22690114/internet-explorer-11-wont-set-cookies-on-a-site/34766660#34766660) and [this article](https://weblog.west-wind.com/posts/2012/Apr/25/Internet-Explorer-and-Cookie-Domains) for more information. Besides, you could try to use `HttpContext.Current.Response.Cookies.Add(myCookie);`. – Yu Zhou Feb 20 '20 at 05:29

0 Answers0