HttpRequestHeaderCollection.Host Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
public:
property HostName ^ Host { HostName ^ get(); void set(HostName ^ value); };
HostName Host();
void Host(HostName value);
public HostName Host { get; set; }
var hostName = httpRequestHeaderCollection.host;
httpRequestHeaderCollection.host = hostName;
Public Property Host As HostName
Property Value
The HostName that represents the value of a Host HTTP header on an HTTP request. A null value means that the header is absent.
Remarks
The following sample code shows a method to set the Host header on an HttpRequestMessage object using the Host property on the HttpRequestHeaderCollection object.
public void DemonstrateHeaderRequestHost() {
var request = new HttpRequestMessage();
// This is not typically set with a string.
// Set the header with a strong type.
// HostName is in the Windows.Networking namespace.
var value = new Windows.Networking.HostName("example.com");
request.Headers.Host = value;
// Get the strong type out
System.Diagnostics.Debug.WriteLine("Canonical Host name: {0}", request.Headers.Host.CanonicalName);
// The ToString() is useful for diagnostics, too.
System.Diagnostics.Debug.WriteLine("The Host ToString() results: {0}", request.Headers.Host.ToString());
}