共用方式為


HttpResponseHeaderCollection.WwwAuthenticate 屬性

定義

取得 HttpChallengeHeaderValueCollection的 HttpChallengeHeaderValue 物件,這些物件代表 HTTP 回應上 WWW-Authenticate HTTP 標頭的值。

public:
 property HttpChallengeHeaderValueCollection ^ WwwAuthenticate { HttpChallengeHeaderValueCollection ^ get(); };
HttpChallengeHeaderValueCollection WwwAuthenticate();
public HttpChallengeHeaderValueCollection WwwAuthenticate { get; }
var httpChallengeHeaderValueCollection = httpResponseHeaderCollection.wwwAuthenticate;
Public ReadOnly Property WwwAuthenticate As HttpChallengeHeaderValueCollection

屬性值

HttpChallengeHeaderValue物件的集合,這些物件代表 HTTP 回應上WWW-Authenticate HTTP 標頭的值。 空集合表示標頭不存在。

備註

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

// WWW-Authenticate: Basic
// HttpChallengeHeaderValueCollection
// HttpChallengeHeaderValue has Scheme and Token (both string) and Parameters (IList<HtpNameValueHeaderValue>)
// IList<HtpNameValueHeaderValue>
// HtpNameValueHeaderValue
    void DemoWwwAuthenticate(HttpResponseMessage response) {
        var h = response.Headers;
        h.WwwAuthenticate.TryParseAdd("Basic");
        h.WwwAuthenticate.Add(new HttpChallengeHeaderValue("scheme", "token"));

        var header = h.WwwAuthenticate;
        uiLog.Text += "\nWWW AUTHENTICATE HEADER\n";
        foreach (var item in header) {
            // Parameters is an IList<HttpNameValueHeaderValue> of Name/Value strings
            var parameterString = "";
            foreach (var parameter in item.Parameters) {
                    parameterString += string.Format("[{0}={1}] ", parameter.Name, parameter.Value);
            }
            if (parameterString == "") {
                parameterString = "(no parameters)";
            }
            uiLog.Text += string.Format("Scheme: {0} Token: {1} Parameters: {2} ToString(): {3}\n", item.Scheme, item.Token, parameterString, item.ToString());
        }
        uiLog.Text += String.Format("WwwAuthenticate: {0}\n", header.ToString());
    }

適用於

另請參閱