Jaa


HttpResponseHeaderCollection.WwwAuthenticate Property

Definition

Gets the HttpChallengeHeaderValueCollection of HttpChallengeHeaderValue objects that represent the value of a WWW-Authenticate HTTP header on an HTTP response.

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

Property Value

The collection of HttpChallengeHeaderValue objects that represent the value of a WWW-Authenticate HTTP header on an HTTP response. An empty collection means that the header is absent.

Remarks

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

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

Applies to

See also