HttpResponseHeaderCollection.Allow 屬性

定義

取得 HttpMethodHeaderValueCollectionHttpMethod 物件,代表 HTTP 回應上 Allow HTTP 標頭的值。

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

屬性值

HttpMethod物件的集合,代表 HTTP 回應上Allow HTTP 標頭的值。 空集合表示標頭不存在。

備註

Allow 屬性代表 HTTP 回應上 Allow HTTP 標頭的值。 Allow標頭是 HTTP 伺服器所允許 (GET、PUT 和 POST 的 HTTP 方法清單,例如) 。

下列範例程式碼示範使用HttpResponseHeaderCollection物件上的 Allow 屬性,取得及設定HttpResponseMessage物件上的Allow標頭的方法。

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());
}

適用於

另請參閱