0

I am working with Asp.Net MVC and in that I am handling cookies like below :

Response.Expires = 0;
Response.Buffer = true;
Response.ClearContent();
Response.AddHeader("content-disposition", "inline; filename=" + "UserData.pdf");
Response.ContentType = "application/pdf";
Response.BinaryWrite(ms.ToArray());

HttpCookie cookie = new HttpCookie("user", UserId.ToString());
HttpCookie cookieProd = new HttpCookie("prod", ProjectId.ToString());

Response.Cookies.Add(cookie);
Response.Cookies.Add(cookieProd);

HttpCookie cookieProd = HttpContext.Request.Cookies.Get("prod");
HttpCookie cookieUser = HttpContext.Request.Cookies.Get("user");

Which is working perfectly in Chrome however it's not working in Internet Explorer 11. When I am login second time then it's not maintaining cookie for use second time login. So can you help me to solve this one for particular Internet Explorer 11 ?

Harry R
  • 69
  • 1
  • 11
  • Check this post. It is possible that IE's zone restrictions are preventing non-http-only cookies to be stored. https://social.technet.microsoft.com/Forums/ie/en-US/e372a61b-1788-40be-83d1-e1f679965534/ie-11-does-not-sent-request-cookies?forum=ieitprocurrentver – Oguz Ozgul Feb 24 '20 at 05:46
  • @OguzOzgul I have check and apply points which suggest in link sent by you. But still when I am trying second time then it's now showing details containing cookies in internet explorer. Should I change any thing in code ? – Harry R Feb 24 '20 at 11:50
  • Dear @harry-r, Are you saying that the cookies in IE11 are being sent back now? I think this was what you were trying to achieve. Can you please elaborate a little bit? In the Network tab of developer tools, are you seeing the request cookies being sent, or not? You can also check the response to see if the cookies are coming from the server, which I think they are. – Oguz Ozgul Feb 24 '20 at 19:26
  • Also in the source code you have posted, you are reading the cookies AFTER setting them to the response. Shouldn't it be the other way around? First read the cookies from the request and set the 'UserId' and 'ProjectId' variables – Oguz Ozgul Feb 24 '20 at 19:28
  • Do you mean that the issue has been resolved after applying the settings in IE? If so, I think it's the cookie policy of IE which leads to the problem and not related to your code. If the issue is resolved, you could suggest OguzOzgul make the solution as an answer and accept his answer, it can help other community members in future in similar kind of issues. Thanks for your understanding. – Yu Zhou Feb 25 '20 at 04:22
  • @OguzOzgul Thanks for your help. Actually my code which I mentioned above is working well with all other browsers but only IE making issue for handling cookie. When I am on IE for first time then cookie is working for all sub tabs but when I close IE browser and reopen it then it's not working. – Harry R Feb 25 '20 at 05:23
  • Dear @harry-r. Can you check this post (If you have not already): https://stackoverflow.com/questions/22690114/internet-explorer-11-wont-set-cookies-on-a-site – Oguz Ozgul Feb 25 '20 at 10:36
  • I've met this kind of issues before. That might because the new changes in cookies and the cookie now had a `SameSite=Lax` attribute. You could refer to these similar threads: [link1](https://stackoverflow.com/questions/60193497/samesite-none-w-secure-breaking-iframe-in-ie11/60202045#60202045), [link2](https://stackoverflow.com/questions/60076007/internet-explorer-edge-not-chromium-add-additional-samesite-lax-when-samesite), to see if the solution adding `cookieSameSite="None"` can solve your problem. – Yu Zhou Feb 26 '20 at 09:34

0 Answers0