Export (0) Print
Expand All

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.
    reader.Close();     

  }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft