I was trying to modify a HTTP Header using C#. I tried to manipulate the Request.Headers on Page preinit event. But when i try to set anything to the Headers, i get PlatformNotSupportedException. Since We can not set a new NameValueCollection to Reqeust.Headers, I tried to set the value using following code:
Request.Headers.Set(HttpRequestHeader.UserAgent.ToString(), "some value");
Any idea how can this be achieved?
Try this:
EDIT: This could be your reason: http://bigjimindc.blogspot.com/2007/07/ms-kb928365-aspnet-requestheadersadd.html
There is a code snippet in that, which adds a new header to the Request.Headers. Verified on Windows 7 32 bit OS too.
But you might want to replace the line:
with:
EDIT: To replace the existing Header value, use:
where "Host" is a Header name.
Adding the complete (working) code from the linked blog - incase that blog vanishes