Condividi tramite


HttpResponseHeaderCollection.Allow Property

Definition

Gets the HttpMethodHeaderValueCollection of HttpMethod objects that represent the value of an Allow HTTP header on an HTTP response.

public:
 property HttpMethodHeaderValueCollection ^ Allow { HttpMethodHeaderValueCollection ^ get(); };
HttpMethodHeaderValueCollection Allow();
public HttpMethodHeaderValueCollection Allow { get; }
var httpMethodHeaderValueCollection = httpResponseHeaderCollection.allow;
Public ReadOnly Property Allow As HttpMethodHeaderValueCollection

Property Value

The collection of HttpMethod objects that represent the value of an Allow HTTP header on an HTTP response. An empty collection means that the header is absent.

Remarks

The Allow property represents the value of an Allow HTTP header on an HTTP response. The Allow header is a list of HTTP methods (GET, PUT, and POST, for example) allowed by the HTTP server.

The following sample code shows a method to get and set the Allow header on an HttpResponseMessage object using the Allow property on the HttpResponseHeaderCollection object.

public void DemonstrateHeaderResponseAllow() {
    var response = new HttpResponseMessage();

    // Set the header with a string
    response.Headers.Allow.TryParseAdd ("GET");

    // Set the header with a strong type
    response.Headers.Allow.Add(HttpMethod.Patch);

    // Get the strong type out
    foreach (var value in response.Headers.Allow) {
        System.Diagnostics.Debug.WriteLine("Allow value: {0}", value.Method);
    }

    // The ToString() is useful for diagnostics, too.
    System.Diagnostics.Debug.WriteLine("The Allow ToString() results: {0}", response.Headers.Allow.ToString());
}

Applies to

See also