0

I have a cookie that holds a tmp file name for backend processing.

    try {
        var cookie = new HttpCookie("TargetExcelFile") {
            Name = "TargetExcelFile",
            Path = "/",
            Secure = true,
            Expires = DateTime.Now.AddDays(1d),
            Value = file
        };

        Response.Cookies.Add(cookie);
    } catch (Exception e) {
        throw new Exception("Create file cookie failed: " + e.Message);
    }

In production it works fine but on localhost the value in the browser is blank. I can set breakpoints and see that the cookie has a value in both cases at the Response.Cookies.Add(cookie); line.

When run on localhost the cookie is created but with no value in the browser.

I had the thought that the Secure flag might be an issue on localhost so I did the following:

    try {
        var cookie = new HttpCookie("TargetExcelFile") {
            Name = "TargetExcelFile",
            Path = "/",
#if DEBUG
            Secure = false,
#else
            Secure = true,
#endif
            Expires = DateTime.Now.AddDays(1d),
            Value = file
        };

        Response.Cookies.Add(cookie);
    } catch (Exception e) {
        throw new Exception("Create file cookie failed: " + e.Message);
    }

... it didn't help.

Ideas?

7 Reeds
  • 2,419
  • 3
  • 32
  • 64

1 Answers1

1

Maybe the domain attribute on the httpCookies node is set to a specific domain. Remove the domain name for development:

<httpCookies httpOnlyCookies="true" requireSSL="false" />

This settings is in the web.config file under system.web.

See more info in this question.

Community
  • 1
  • 1
Dávid Molnár
  • 10,673
  • 7
  • 30
  • 55