The System.Net namespace in C# includes the CookieContainer class, which allows developers to handle cookies in HTTP requests and responses. The Add method of the CookieContainer class adds a new cookie to the container.
Example 1: CookieContainer cookies = new CookieContainer(); Uri uri = new Uri("https://www.example.com"); Cookie newCookie = new Cookie("sessionId", "12345"); cookies.Add(uri, newCookie);
This example adds a new cookie with name "sessionId" and value "12345" to the cookie container for the domain "https://www.example.com".
Example 2: CookieContainer cookies = new CookieContainer(); Uri uri1 = new Uri("https://www.example.com"); Cookie cookie1 = new Cookie("sessionId", "12345"); Uri uri2 = new Uri("https://subdomain.example.com"); Cookie cookie2 = new Cookie("userId", "67890"); cookies.Add(uri1, cookie1); cookies.Add(uri2, cookie2);
This example adds two cookies to the cookie container for two different domains - "https://www.example.com" and "https://subdomain.example.com".
The CookieContainer class is part of the System.Net package library.
C# (CSharp) System.Net CookieContainer.Add - 46 examples found. These are the top rated real world C# (CSharp) examples of System.Net.CookieContainer.Add extracted from open source projects. You can rate examples to help us improve the quality of examples.