David Merrilees
David Merrilees

Reputation: 2490

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?

Upvotes: 1

Views: 1480

Answers (2)

Ant P
Ant P

Reputation: 25221

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.

Upvotes: 4

UNOWN301
UNOWN301

Reputation: 29

To my understanding, no. If you change the response cookies, it should not change the request cookies unless you specifically set them equal to each other or something like that.

Upvotes: 0

Related Questions