Information
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.

[Visual Basic]
Property Credentials As ICredentials
[C#]
ICredentials Credentials {set;}
[C++]
public: __property virtual void set_Credentials(ICredentials*) = 0;
[JScript]
public abstract function set Credentials(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.

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 for the virtual directory "http://localhost/bookstore/inventory.xml"

XmlTextReader reader = new XmlTextReader("http://localhost/bookstore/inventory.xml");
NetworkCredential nc = new NetWorkCredential(UserName,SecurelyStoredPassword,Domain);
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = nc;
reader.XmlResolver= resolver;
   

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("http://www.contoso.com/"), "Basic", myCred); 
myCache.Add(new Uri("http://app.contoso.com/"), "Basic", myCred);
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = myCache;
reader.XmlResolver = resolver;
   

Example

See XmlUrlResolver.Credentials for an example using this property.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlResolver Class | XmlResolver Members | System.Xml Namespace | CredentialCache | NetworkCredential

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft