The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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 */
public abstract void set_Credentials (ICredentials value)

public abstract function set Credentials (value : ICredentials)

Property Value

An ICredentials object. If this property is not set, the value defaults to a null reference (Nothing in Visual Basic); 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;

See XmlUrlResolver.Credentials for an example using this property.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft