When overridden in a derived class, sets the credentials used to authenticate web requests.
Assembly: System.Xml (in System.Xml.dll)
abstract Credentials : ICredentials with set override Credentials : ICredentials with set
Property ValueType: System.Net.ICredentials
The credentials to be used to authenticate web requests. 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 doesn't have 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;
You can associate different credentials with different URIs and add them to a cache. You can then use the credentials 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;
Available since 1.1