Microsoft Silverlight will reach end of support after October 2021. Learn more.
Contains protocol headers associated with a request or response.
Assembly: System.Net (in System.Net.dll)
'Declaration <DefaultMemberAttribute("Item")> _ Public NotInheritable Class WebHeaderCollection _ Implements IEnumerable
[DefaultMemberAttribute("Item")] public sealed class WebHeaderCollection : IEnumerable
The WebHeaderCollection type exposes the following members.
|WebHeaderCollection||Initializes a new instance of the WebHeaderCollection class.|
|AllKeys||Gets the collection of header name/value pairs associated with the request.|
|Count||Gets the number of headers in the collection.|
|Item[HttpRequestHeader]||Gets or sets the specified request header.|
|Item[String]||Gets or sets the specified request header.|
|Equals(Object)||Determines whether the specified Object is equal to the current Object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as a hash function for a particular type. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|ToString||Returns a string that represents the current object. (Inherited from Object.)
In Silverlight for Windows Phone, this member is overridden by ToString().
In XNA Framework, this member is overridden by ToString().
|AsQueryable||Converts an IEnumerable to an IQueryable. (Defined by Queryable.)|
|Cast<TResult>||Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)|
|OfType<TResult>||Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)|
Explicit Interface Implementations
|IEnumerable.GetEnumerator||Returns an enumerator that can iterate through the WebHeaderCollection instance.|
The WebHeaderCollection class is generally accessed through WebRequest.Headers property.
The Item property can be used to get the value of a header stored in a WebHeaderCollection object. The Item[HttpRequestHeader] property can be used to get the value of common headers defined in the HttpRequestHeader enumeration. The Item[String] property can be used to get the value of custom headers and those headers not defined in the HttpRequestHeader enumeration.
Some common headers are considered restricted and are either exposed directly (such as Content-Type) or protected by the system and cannot be set or changed in a WebHeaderCollection object. Any attempt to set one of these restricted headers in the WebHeaderCollection object associated with a HttpWebRequest object throws an exception. Any attempt to set one of these restricted headers in the WebHeaderCollection object associated with a WebClient object will throw an exception later when attempting to send the WebClient request.
Restricted headers include, but are not limited to the following:
Many of these restricted headers are set by the web browser that hosts the Silverlight application.
In addition, some headers are also restricted when the Method property is set to an HTTP GET protocol verb. These restricted headers include, but are not limited to the following:
In addition, some headers are also restricted when the Method property is set to an HTTP POST protocol verb. These restricted headers include, but are not limited to the following:
For security reasons, the Silverlight runtime restricts sending specific headers to a cross-domain site unless the header is allowed by the security policy applicable to the target cross-domain site. This restriction applies to resources from locations other than the site of origin. The Authorization header can be set using the Headers property. However to set the credentials properly, the cross-domain policy applicable to the target must have the http-request-headers set to allow the Authorization header to be sent. For more information, see Network Security Access Restrictions in Silverlight and URL Access Restrictions in Silverlight.
You should not assume that the header values will remain unchanged, because Web servers and caches may change or add headers to a Web request.
The Mozilla FireFox browser does not currently set the Referer header on HTTP GET requests. The Internet Explorer and Safari web browsers do properly set the Referer header on HTTP GET requests. As a result, a Silverlight application hosted in Firefox can't support the Referer header being set on any GET requests applicable to browser HTTP handling for BrowserHttp. The Referer header is properly set on HTTP POST requests by Firefox, Internet Explorer, and Safari applicable to browser HTTP handling for BrowserHttp.
The Referer header is properly set on all HTTP requests applicable to client HTTP handling for ClientHttp regardless of the web browser.
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
Supported in: Windows Phone OS 7.0
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.