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 ?

8
  • Check this post. It is possible that IE's zone restrictions are preventing non-http-only cookies to be stored. social.technet.microsoft.com/Forums/ie/en-US/…
    – Oguz Ozgul
    Commented Feb 24, 2020 at 5: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
    Commented Feb 24, 2020 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
    Commented Feb 24, 2020 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
    Commented Feb 24, 2020 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
    Commented Feb 25, 2020 at 4:22

0