HttpWebRequest.Headers["Host"] throws an unexpected exception. - by aptitude

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


7
1
Sign in
to vote
ID 384456 Comments
Status Closed Workarounds
Type Bug Repros 3
Opened 11/27/2008 3:34:40 AM
Access Restriction Public

Description

It seems that there is no way to modify the Host header for a WebRequest. When you try to set the HttpWebRequest.Headers[“Host”] property you get an ArgumentException with the message “The 'Host' header cannot be modified directly”. If the Host header can be modified indirectly it would be helpful if somewhere in the error or in MSDN an indication of how this is done could be given.

It is important to be able to change the Host header for anyone testing web sites on a shared hosting environment before the DNS settings have been set. It is also needed when writing diagnostic tools for sites hosted behind load balancers.
Sign in to post a comment.
Posted by aptitude on 5/27/2009 at 2:16 AM
Cool, I'll look forward to testing that out.
Posted by Microsoft on 5/26/2009 at 1:37 PM
The next release of the .NET Framework will include a new "Host" property. The value of this property will be sent as "Host" header in the HTTP request.
Posted by Jeffrey Brown on 5/15/2009 at 5:22 PM
I was also hoping to be able to spoof the host header because we have some services that we need to connect to directly for internal use but that expect to be reached normally using a particular external name through our load balancer. Effectively we want to remove the load balancer from the pipe for certain internal requests but we want the site to think that it is being reached using the same host name because the content it returns may contain absolute Uris that include the host name.

We could modify System32\Drivers\etc\hosts but doing so has a global impact on the machine whereas we only wish to spoof individual requests. Likewise we could probably modify the services being being accessed but we really shouldn't have to for this purpose.
Posted by David [MSFT] on 3/3/2009 at 7:32 PM
We are investigating this issue for possible inclusion in the next release of the .NET Framework.

Thank you,

Network Class Library Team
Posted by Microsoft on 11/27/2008 at 11:49 PM
Thanks for your feedback. We are escalating this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Posted by aptitude on 11/27/2008 at 5:39 AM
Unfortunatly my company firewall does not allow me to make an outbound connection to a proxy, so the WebProxy work arround does not work for me. It may work for other people though.