This documentation is archived and is not being maintained.

XmlResolver.Credentials Property

When overridden in a derived class, sets the credentials used to authenticate Web requests.

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

public abstract ICredentials Credentials { set; }

Property Value

Type: System.Net.ICredentials
An ICredentials object. If this property is not set, the value defaults to null; that is, the XmlResolver has no user credentials.

If the virtual directory does not require authentication, this property does not need to be set. Otherwise, the credentials of the user must be supplied.

The following C# code sets credentials on the XmlResolver object.

NetworkCredential nc = new NetWorkCredential(UserName,SecurelyStoredPassword,Domain);
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = nc;

Different credentials can be associated with different URIs and added to a credential cache. The credentials can then be used to check authentication for different URIs regardless of the original source of the XML.

NetworkCredential myCred = new NetworkCredential(UserName,SecurelyStoredPassword,Domain); 
CredentialCache myCache = new CredentialCache(); 
myCache.Add(new Uri(""), "Basic", myCred); 
myCache.Add(new Uri(""), "Basic", myCred);
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = myCache;

This member may behave differently when it is used in a Portable Class Library project. For more information, see API Differences in Portable Class Library.

See XmlUrlResolver.Credentials for an example using this property.

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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