Provides a collection of the HTTP headers associated with a request or response.
Inheritance
System.Object
System.Collections.Specialized.NameObjectCollectionBase
System.Collections.Specialized.NameValueCollection
WebHeaderCollection
Implements
System.Collections.ICollection
System.Collections.IEnumerable
System.Runtime.Serialization.IDeserializationCallback
System.Runtime.Serialization.ISerializable
Inherited Members
System.Collections.Specialized.NameValueCollection.Add(System.Collections.Specialized.NameValueCollection)
System.Collections.Specialized.NameValueCollection.CopyTo(System.Array, System.Int32)
System.Collections.Specialized.NameValueCollection.Get(System.Int32)
System.Collections.Specialized.NameValueCollection.Get(System.String)
System.Collections.Specialized.NameValueCollection.GetKey(System.Int32)
System.Collections.Specialized.NameValueCollection.HasKeys()
System.Collections.Specialized.NameValueCollection.InvalidateCachedArrays()
System.Collections.Specialized.NameValueCollection.AllKeys
System.Collections.Specialized.NameValueCollection.Item[System.Int32]
System.Collections.Specialized.NameValueCollection.Item[System.String]
System.Collections.Specialized.NameObjectCollectionBase.BaseAdd(System.String, System.Object)
System.Collections.Specialized.NameObjectCollectionBase.BaseClear()
System.Collections.Specialized.NameObjectCollectionBase.BaseGet(System.Int32)
System.Collections.Specialized.NameObjectCollectionBase.BaseGet(System.String)
System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllKeys()
System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllValues()
System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllValues(System.Type)
System.Collections.Specialized.NameObjectCollectionBase.BaseGetKey(System.Int32)
System.Collections.Specialized.NameObjectCollectionBase.BaseHasKeys()
System.Collections.Specialized.NameObjectCollectionBase.BaseRemove(System.String)
System.Collections.Specialized.NameObjectCollectionBase.BaseRemoveAt(System.Int32)
System.Collections.Specialized.NameObjectCollectionBase.BaseSet(System.Int32, System.Object)
System.Collections.Specialized.NameObjectCollectionBase.BaseSet(System.String, System.Object)
System.Collections.Specialized.NameObjectCollectionBase.GetEnumerator()
System.Collections.Specialized.NameObjectCollectionBase.System.Collections.ICollection.CopyTo(System.Array, System.Int32)
System.Collections.Specialized.NameObjectCollectionBase.Count
System.Collections.Specialized.NameObjectCollectionBase.IsReadOnly
System.Collections.Specialized.NameObjectCollectionBase.Keys
System.Collections.Specialized.NameObjectCollectionBase.System.Collections.ICollection.IsSynchronized
System.Collections.Specialized.NameObjectCollectionBase.System.Collections.ICollection.SyncRoot
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Assembly: Mars.Common.dll
[Serializable]
[ComVisible(true)]
public class WebHeaderCollection : NameValueCollection, ICollection, IEnumerable, IDeserializationCallback, ISerializable
Constructors
|
Improve this Doc
View Source
Declaration
public WebHeaderCollection()
|
Improve this Doc
View Source
Initializes a new instance of the
WebHeaderCollection class from
the specified
System.Runtime.Serialization.SerializationInfo and
System.Runtime.Serialization.StreamingContext.
Declaration
protected WebHeaderCollection(SerializationInfo serializationInfo, StreamingContext streamingContext)
Parameters
Type |
Name |
Description |
System.Runtime.Serialization.SerializationInfo |
serializationInfo |
A System.Runtime.Serialization.SerializationInfo that contains the serialized object data.
|
System.Runtime.Serialization.StreamingContext |
streamingContext |
A System.Runtime.Serialization.StreamingContext that specifies the source for the deserialization.
|
Exceptions
Type |
Condition |
System.ArgumentNullException |
serializationInfo is null.
|
System.ArgumentException |
An element with the specified name isn't found in serializationInfo .
|
Properties
|
Improve this Doc
View Source
Gets or sets the specified request header
in the collection.
Declaration
public string this[HttpRequestHeader header] { get; set; }
Parameters
Type |
Name |
Description |
System.Net.HttpRequestHeader |
header |
One of the System.Net.HttpRequestHeader enum values, represents
the request header to get or set.
|
Property Value
Type |
Description |
System.String |
A System.String that represents the value of the request header .
|
Exceptions
Type |
Condition |
System.ArgumentException |
header is a restricted header.
-or-
value contains invalid characters.
|
System.ArgumentOutOfRangeException |
The length of value is greater than 65,535 characters.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the request header .
|
|
Improve this Doc
View Source
Gets or sets the specified response header
in the collection.
Declaration
public string this[HttpResponseHeader header] { get; set; }
Parameters
Type |
Name |
Description |
System.Net.HttpResponseHeader |
header |
One of the System.Net.HttpResponseHeader enum values, represents
the response header to get or set.
|
Property Value
Type |
Description |
System.String |
A System.String that represents the value of the response header .
|
Exceptions
Type |
Condition |
System.ArgumentException |
header is a restricted header.
-or-
value contains invalid characters.
|
System.ArgumentOutOfRangeException |
The length of value is greater than 65,535 characters.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the response header .
|
Methods
|
Improve this Doc
View Source
Adds the specified request header
with
the specified value
to the collection.
Declaration
public void Add(HttpRequestHeader header, string value)
Parameters
Type |
Name |
Description |
System.Net.HttpRequestHeader |
header |
One of the System.Net.HttpRequestHeader enum values, represents
the request header to add.
|
System.String |
value |
A System.String that represents the value of the header to add.
|
Exceptions
Type |
Condition |
System.ArgumentException |
header is a restricted header.
-or-
value contains invalid characters.
|
System.ArgumentOutOfRangeException |
The length of value is greater than 65,535 characters.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the request header .
|
|
Improve this Doc
View Source
Adds the specified response header
with
the specified value
to the collection.
Declaration
public void Add(HttpResponseHeader header, string value)
Parameters
Type |
Name |
Description |
System.Net.HttpResponseHeader |
header |
One of the System.Net.HttpResponseHeader enum values, represents
the response header to add.
|
System.String |
value |
A System.String that represents the value of the header to add.
|
Exceptions
Type |
Condition |
System.ArgumentException |
header is a restricted header.
-or-
value contains invalid characters.
|
System.ArgumentOutOfRangeException |
The length of value is greater than 65,535 characters.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the response header .
|
|
Improve this Doc
View Source
Adds a header with the specified name
and
value
to the collection.
Declaration
public override void Add(string name, string value)
Parameters
Type |
Name |
Description |
System.String |
name |
A System.String that represents the name of the header to add.
|
System.String |
value |
A System.String that represents the value of the header to add.
|
Overrides
System.Collections.Specialized.NameValueCollection.Add(System.String, System.String)
Exceptions
Type |
Condition |
System.ArgumentNullException |
name is null or empty.
|
System.ArgumentException |
name or value contains invalid characters.
-or-
name is a restricted header name.
|
System.ArgumentOutOfRangeException |
The length of value is greater than 65,535 characters.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the header name .
|
|
Improve this Doc
View Source
Adds the specified header
to the collection.
Declaration
public void Add(string header)
Parameters
Type |
Name |
Description |
System.String |
header |
A System.String that represents the header with the name and value separated by
a colon (':' ).
|
Exceptions
Type |
Condition |
System.ArgumentNullException |
header is null, empty, or the name part of
header is empty.
|
System.ArgumentException |
header doesn't contain a colon.
-or-
header is a restricted header.
-or-
The name or value part of header contains invalid characters.
|
System.ArgumentOutOfRangeException |
The length of the value part of header is greater than 65,535 characters.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the header .
|
|
Improve this Doc
View Source
Adds a header to the collection without checking if the header is on
the restricted header list.
Declaration
protected void AddWithoutValidate(string headerName, string headerValue)
Parameters
Type |
Name |
Description |
System.String |
headerName |
A System.String that represents the name of the header to add.
|
System.String |
headerValue |
A System.String that represents the value of the header to add.
|
Exceptions
Type |
Condition |
System.ArgumentNullException |
headerName is null or empty.
|
System.ArgumentException |
headerName or headerValue contains invalid characters.
|
System.ArgumentOutOfRangeException |
The length of headerValue is greater than 65,535 characters.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the headerName .
|
|
Improve this Doc
View Source
Removes all headers from the collection.
Declaration
public override void Clear()
Overrides
System.Collections.Specialized.NameValueCollection.Clear()
|
Improve this Doc
View Source
Populates the specified
System.Runtime.Serialization.SerializationInfo with the data needed to serialize
the
WebHeaderCollection.
Declaration
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
public override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
Parameters
Type |
Name |
Description |
System.Runtime.Serialization.SerializationInfo |
serializationInfo |
A System.Runtime.Serialization.SerializationInfo that holds the serialized object data.
|
System.Runtime.Serialization.StreamingContext |
streamingContext |
A System.Runtime.Serialization.StreamingContext that specifies the destination for the serialization.
|
Overrides
System.Collections.Specialized.NameObjectCollectionBase.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)
Exceptions
Type |
Condition |
System.ArgumentNullException |
serializationInfo is null.
|
|
Improve this Doc
View Source
Gets an array of header values stored in the specified index
position of
the collection.
Declaration
public override string[] GetValues(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
An System.Int32 that represents the zero-based index of the header to find.
|
Returns
Type |
Description |
System.String[] |
An array of System.String that receives the header values if found;
otherwise, null.
|
Overrides
System.Collections.Specialized.NameValueCollection.GetValues(System.Int32)
Exceptions
Type |
Condition |
System.ArgumentOutOfRangeException |
index is out of allowable range of indexes for the collection.
|
|
Improve this Doc
View Source
Gets an array of header values stored in the specified header
.
Declaration
public override string[] GetValues(string header)
Parameters
Type |
Name |
Description |
System.String |
header |
A System.String that represents the name of the header to find.
|
Returns
Type |
Description |
System.String[] |
An array of System.String that receives the header values if found;
otherwise, null.
|
Overrides
System.Collections.Specialized.NameValueCollection.GetValues(System.String)
|
Improve this Doc
View Source
Determines whether the specified header can be set for the request or the response.
Declaration
public static bool IsRestricted(string headerName, bool response)
Parameters
Type |
Name |
Description |
System.String |
headerName |
A System.String that represents the name of the header to test.
|
System.Boolean |
response |
true if does the test for the response; for the request, false .
|
Returns
Type |
Description |
System.Boolean |
true if the header is restricted; otherwise, false .
|
Exceptions
Type |
Condition |
System.ArgumentNullException |
headerName is null or empty.
|
System.ArgumentException |
headerName contains invalid characters.
|
|
Improve this Doc
View Source
Determines whether the specified header can be set for the request.
Declaration
public static bool IsRestricted(string headerName)
Parameters
Type |
Name |
Description |
System.String |
headerName |
A System.String that represents the name of the header to test.
|
Returns
Type |
Description |
System.Boolean |
true if the header is restricted; otherwise, false .
|
Exceptions
Type |
Condition |
System.ArgumentNullException |
headerName is null or empty.
|
System.ArgumentException |
headerName contains invalid characters.
|
|
Improve this Doc
View Source
Implements the System.Runtime.Serialization.ISerializable interface and raises the deserialization event
when the deserialization is complete.
Declaration
public override void OnDeserialization(object sender)
Parameters
Type |
Name |
Description |
System.Object |
sender |
An System.Object that represents the source of the deserialization event.
|
Overrides
System.Collections.Specialized.NameObjectCollectionBase.OnDeserialization(System.Object)
|
Improve this Doc
View Source
Removes the specified request header
from the collection.
Declaration
public void Remove(HttpRequestHeader header)
Parameters
Type |
Name |
Description |
System.Net.HttpRequestHeader |
header |
One of the System.Net.HttpRequestHeader enum values, represents
the request header to remove.
|
Exceptions
Type |
Condition |
System.ArgumentException |
header is a restricted header.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the request header .
|
|
Improve this Doc
View Source
Removes the specified response header
from the collection.
Declaration
public void Remove(HttpResponseHeader header)
Parameters
Type |
Name |
Description |
System.Net.HttpResponseHeader |
header |
One of the System.Net.HttpResponseHeader enum values, represents
the response header to remove.
|
Exceptions
Type |
Condition |
System.ArgumentException |
header is a restricted header.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the response header .
|
|
Improve this Doc
View Source
Removes the specified header from the collection.
Declaration
public override void Remove(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
A System.String that represents the name of the header to remove.
|
Overrides
System.Collections.Specialized.NameValueCollection.Remove(System.String)
Exceptions
Type |
Condition |
System.ArgumentNullException |
name is null or empty.
|
System.ArgumentException |
name contains invalid characters.
-or-
name is a restricted header name.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the header name .
|
|
Improve this Doc
View Source
Sets the specified request header
to the specified value.
Declaration
public void Set(HttpRequestHeader header, string value)
Parameters
Type |
Name |
Description |
System.Net.HttpRequestHeader |
header |
One of the System.Net.HttpRequestHeader enum values, represents
the request header to set.
|
System.String |
value |
A System.String that represents the value of the request header to set.
|
Exceptions
Type |
Condition |
System.ArgumentException |
header is a restricted header.
-or-
value contains invalid characters.
|
System.ArgumentOutOfRangeException |
The length of value is greater than 65,535 characters.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the request header .
|
|
Improve this Doc
View Source
Sets the specified response header
to the specified value.
Declaration
public void Set(HttpResponseHeader header, string value)
Parameters
Type |
Name |
Description |
System.Net.HttpResponseHeader |
header |
One of the System.Net.HttpResponseHeader enum values, represents
the response header to set.
|
System.String |
value |
A System.String that represents the value of the response header to set.
|
Exceptions
Type |
Condition |
System.ArgumentException |
header is a restricted header.
-or-
value contains invalid characters.
|
System.ArgumentOutOfRangeException |
The length of value is greater than 65,535 characters.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the response header .
|
|
Improve this Doc
View Source
Sets the specified header to the specified value.
Declaration
public override void Set(string name, string value)
Parameters
Type |
Name |
Description |
System.String |
name |
A System.String that represents the name of the header to set.
|
System.String |
value |
A System.String that represents the value of the header to set.
|
Overrides
System.Collections.Specialized.NameValueCollection.Set(System.String, System.String)
Exceptions
Type |
Condition |
System.ArgumentNullException |
name is null or empty.
|
System.ArgumentException |
name or value contains invalid characters.
-or-
name is a restricted header name.
|
System.ArgumentOutOfRangeException |
The length of value is greater than 65,535 characters.
|
System.InvalidOperationException |
The current WebHeaderCollection instance doesn't allow
the header name .
|
|
Improve this Doc
View Source
Declaration
public byte[] ToByteArray()
Returns
Type |
Description |
System.Byte[] |
An array of System.Byte that receives the converted current
WebHeaderCollection.
|
|
Improve this Doc
View Source
Declaration
public override string ToString()
Returns
Type |
Description |
System.String |
A System.String that represents the current WebHeaderCollection.
|
Overrides
System.Object.ToString()
Explicit Interface Implementations
|
Improve this Doc
View Source
Populates the specified
System.Runtime.Serialization.SerializationInfo with the data needed to serialize
the current
WebHeaderCollection.
Declaration
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter, SerializationFormatter = true)]
void ISerializable.GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
Parameters
Type |
Name |
Description |
System.Runtime.Serialization.SerializationInfo |
serializationInfo |
A System.Runtime.Serialization.SerializationInfo that holds the serialized object data.
|
System.Runtime.Serialization.StreamingContext |
streamingContext |
A System.Runtime.Serialization.StreamingContext that specifies the destination for the serialization.
|
Exceptions
Type |
Condition |
System.ArgumentNullException |
serializationInfo is null.
|
Implements
System.Collections.ICollection
System.Collections.IEnumerable
System.Runtime.Serialization.IDeserializationCallback
System.Runtime.Serialization.ISerializable
Extension Methods