Well, you’re probably reading this because you noticed that .NET’s WebClient doesn’t support cookies. Basically, the cookies which are received through the WebRequest are NOT stored and also NOT sent - this is how it works by default.

## How to fix this?

Here, I’ll show you how to make WebClient handle cookies. All you have to do is to add a CookieContainer, this is where the cookies will be stored. Then you’ll just include this CookieContainer in your original request, by overriding GetWebRequest.

I’ll post the code and I’ll explain it using comments:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class ImprovedWebClient : WebClient
{
//^here are automatically stored the cookies

{

if (request is HttpWebRequest)  //if it is a Http request

1