Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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 virtual ICredentials Credentials { set; }

Property Value

Type: 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;

See XmlUrlResolver.Credentials for an example that uses this property.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.