XmlSecureResolver.Credentials Property


Sets credentials used to authenticate web requests.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public override ICredentials Credentials { set; }

Property Value

Type: System.Net.ICredentials

The credentials to be used to authenticate web requests. The XmlSecureResolver sets the given credentials on the underlying XmlResolver. If this property is not set, the value defaults to null; that is, the XmlSecureResolver has no user credentials.

The following example uses an XmlSecureResolver with default credentials to resolve and open network resources needed by the XmlTextReader.

using System;
using System.IO;
using System.Xml;
using System.Net;

public class Sample {

  public static void Main() {

    // Create the reader.
    XmlTextReader reader = new XmlTextReader("http://myServer/data/books.xml");

    // Create a secure resolver with default credentials.
    XmlUrlResolver resolver = new XmlUrlResolver();
    XmlSecureResolver sResolver = new XmlSecureResolver(resolver, "http://myServer/data/");
    sResolver.Credentials = CredentialCache.DefaultCredentials;

    // Use the secure resolver to resolve resources.
    reader.XmlResolver = sResolver;

    // Parse the file.
    while (reader.Read()) {
       // Do any additional processing here.

    // Close the reader.


.NET Framework
Available since 1.1
Return to top