C# allow to add one ore more cookies values in System.Net.WebClient object in ASP.Net using C#. Also, how to format the name and the value of the cookie.
Following are the solution snippets of C# code:
Add Single Cookie
C# allows add cookie in ASP.Net request and response headers as following code
System.Net.WebClient wc = new System.Net.WebClient();
wc.Headers.Add(System.Net.HttpRequestHeader.Cookie, "mycookie1=value1");
The cookie-name and the cookie-value are seperated by = operator.
Add Multiple Cookies
C# allows add multiple cookies in ASP.Net separate each cookie by semicolon ;
System.Net.WebClient wc = new System.Net.WebClient();
wc.Headers.Add(System.Net.HttpRequestHeader.Cookie, "myCookie1=myValue1;myCookie2=myValue2;myCookie3=myValue3");
Web Cookies format
Cookies are stored in browser and sent or receive between server and client as string values.
Posted Status in Programming