C#, Web Application

Adding User-Agent HTTP header to a web request from C# code

Recently I faced a small issue while passing User-Agent as part of Http headers.

I was assuming any header can be passed to a Web Request using request.Headers.Add(“Header Name”, “Value”) but I was wrong.


User-Agent is actually a property on WebRequest and has to be set like the following:



Simple issue but good to remember 🙂