Search code examples
c#asp.netcookieshttpresponseserver-side

Added cookies cannot be retrieved from the IE browser


I'm writing an asp.net application and I am saving the cookies correctly (stored in internet files). When I open the file it contains: access_token mylongalphanumberictoken /domainname (no spaces between them). The problem is that when I check the client for a cookie, I receive null. Can anyone tell me why this is happening and how do i fix it?

public void createCookie(string tokenVal)
        {
            authCookie = new HttpCookie("access_token",tokenVal);
            authCookie.Expires = DateTime.Now.AddDays(60.00); //Token expires in 60 days
            authCookie.Domain = ServerDomain.Authority;
         }

check if the client has cookies like this:

          if (Request.Cookies["access_token"] != null)
               {
                  currentCookieStore.authCookie = Request.Cookies["access_token"];
               }

EDIT: im using: currPage.Response.Cookies.Add(newTokenCookie.OauthCookie) ; to add the cookies. ServerDomain is the location of my webserver so its machinename.domain


Solution

  • The answer is to add a P3P header to prevent IE from blocking your cookies. Solution here:

    Explanation: Cookie blocked/not saved in IFRAME in Internet Explorer

    How to: http://social.msdn.microsoft.com/Forums/windowsazure/en-US/4f74156a-54a0-468b-8496-85913094fc34/issue-while-adding-http-response-header-to-a-site-hosted-in-azure-web-role-running-with-more-than?forum=windowsazuremanagement