David Merrilees David Merrilees - 4 years ago 73
ASP.NET (C#) Question

Does modifying the Response.Cookies collection also change Request.Cookies in .Net?

Just want to check what i'm seeing, modifying the Response.Cookies collection also changes Request.Cookies?

Answer Source

Yes, it does. Try creating a new page with the following in the codebehind:

protected void Page_Load(object sender, EventArgs e)
    if (Request.Cookies["newCookie"] == null)
        Response.Cookies["newCookie"].Value = "Hello, world!";
        var myValue = Request.Cookies["newCookie"].Value;

Clear your cookies and place a breakpoint on the closing brace of the condition. You'll see that myValue has the value "Hello, world!" on the first request.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download