Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

WebHeaderCollection Class

Contains protocol headers associated with a request or response.

System.Object
  System.Net.WebHeaderCollection

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)
[DefaultMemberAttribute("Item")]
public sealed class WebHeaderCollection : IEnumerable

The WebHeaderCollection type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneWebHeaderCollectionInitializes a new instance of the WebHeaderCollection class.
Top
  NameDescription
Public propertySupported by Silverlight for Windows PhoneAllKeysGets the collection of header name/value pairs associated with the request.
Public propertySupported by Silverlight for Windows PhoneCountGets the number of headers in the collection.
Public propertySupported by Silverlight for Windows PhoneItem[HttpRequestHeader]Gets or sets the specified request header.
Public propertySupported by Silverlight for Windows PhoneItem[String]Gets or sets the specified request header.
Top
  NameDescription
Public methodSupported by Silverlight for Windows PhoneEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneToStringReturns 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().
Top
  NameDescription
Public Extension MethodSupported by Silverlight for Windows PhoneAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodSupported by Silverlight for Windows PhoneCast<TResult>Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodSupported by Silverlight for Windows PhoneOfType<TResult>Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top
  NameDescription
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneIEnumerable.GetEnumeratorReturns an enumerator that can iterate through the WebHeaderCollection instance.
Top

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.

The Item property can be used to set custom headers in a WebHeaderCollection object for use by the WebClient or HttpWebRequest objects.

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:

  • Accept

  • Accept-Charset

  • Accept-Encoding

  • Accept-Language

  • Accept-Ranges

  • Age

  • Allow

  • Allowed

  • Connect

  • Connection

  • Content-Length

  • Content-Location

  • Content-Range

  • Content-Transfer-Encoding

  • Content-Type

  • Cookie

  • Date

  • Delete

  • ETag

  • Expect

  • Get

  • Head

  • Host

  • Keep-Alive

  • Last-Modified

  • Location

  • Max-Forwards

  • Options

  • Post

  • Proxy-Authenticate

  • Proxy-Authorization

  • Proxy-Connection

  • Public

  • Put

  • Range

  • Referer

  • Request-Range

  • TE

  • Trace

  • Trailer

  • Transfer-Encoding

  • Upgrade

  • User-Agent

  • Via

  • Warning

  • Uri

  • X-Flash-Version

  • Retry-After

  • Server

  • Vary

  • WWW-Authenticate

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:

  • Content-Encoding

  • Content-Language

  • Content-Location

  • Content-MD5

  • Content-Range

  • Content-Type

  • Expires

  • Last-Modified

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:

  • Content-Location

  • Content-Range

  • Last-Modified

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.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

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.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.