XmlUrlResolver.Credentials Property
Sets credentials used to authenticate Web requests.
Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Property Value
Type: System.Net.ICredentialsAn ICredentials object. If this property is not set, the value defaults to null; that is, the XmlUrlResolver 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.
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.
The following C# code shows how to set the Credentials property to a credential cache.
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;
The following example creates an XmlUrlResolver object with credentials. The XmlReader uses the credentials on the XmlUrlResolver object to access a network resource.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.