HttpResponseHeaderCollection.WwwAuthenticate 属性

定义

获取 HttpChallengeHeaderValue 对象的 HttpChallengeHeaderValueCollection ,这些对象表示 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());
    }

适用于

另请参阅