Link to home
Create AccountLog in
Avatar of arichexe
arichexe

asked on

Replacing a Cookie instance

According to MS, the CookieContainer.SetCookies Method "ADDS Cookie instances for one or more cookies from an HTTP cookie header to the CookieContainer for a specific URI," but what if I wanted to REPLACE a Cookie instance?  The below creates two instances of the same header.  I just want one.

Uri uri = new Uri(url);

Console.WriteLine(MyHttpRequest.CookieContainer.GetCookieHeader(uri));
// displays "MyCookie: MyValue"

MyHttpRequest.CookieContainer.SetCookies(uri,"MyCookie: MyNewValue);

Console.WriteLine(MyHttpRequest.CookieContainer.GetCookieHeader(uri));
// displays "MyCookie: MyNewValue; MyCookie: MyValue," rather than just "MyCookie: MyNewValue"
Avatar of Ted Bouskill
Ted Bouskill
Flag of Canada image

The Request object is what you received from the client.  If you want to send a cookie back you need to use the Response object
Avatar of arichexe
arichexe

ASKER

How would I code that?
ASKER CERTIFIED SOLUTION
Avatar of Ted Bouskill
Ted Bouskill
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account