System.Xml.XmlResolver.Credentials Property

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

Syntax

public virtual System.Net.ICredentials Credentials { set; }

Value

A System.Net.ICredentials instance containing the credentials.

Remarks

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 System.Xml.XmlResolver object.

Example

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.

Example

NetworkCredential myCred = new NetworkCredential(UserName,SecurelyStoredPassword,Domain); 
CredentialCache myCache = new CredentialCache(); 
myCache.Add(new Uri("http://www.contoso.com/"), "Basic", myCred); 
myCache.Add(new Uri("http://app.contoso.com/"), "Basic", myCred);
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = myCache;

Example

See XmlUrlResolver.Credentials for an example using this property.

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0