Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 Credentials Property

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
XmlUrlResolver..::.Credentials Property

Sets credentials used to authenticate Web requests.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
Visual Basic (Declaration)
Public Overrides WriteOnly Property Credentials As ICredentials
Visual Basic (Usage)
Dim instance As XmlUrlResolver
Dim value As ICredentials

instance.Credentials = value
C#
public override ICredentials Credentials { set; }
Visual C++
public:
virtual property ICredentials^ Credentials {
    void set (ICredentials^ value) override;
}
JScript
public override function set Credentials (value : ICredentials)

Property Value

Type: System.Net..::.ICredentials
An ICredentials object. If this property is not set, the value defaults to nullNothingnullptra null reference (Nothing in Visual Basic); 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.

Visual Basic
' Create a resolver and specify the necessary credentials.
Dim resolver As New XmlUrlResolver()
Dim myCred As System.Net.NetworkCredential
myCred = New System.Net.NetworkCredential(UserName, SecurelyStoredPassword, Domain)
resolver.Credentials = myCred


C#
// Create a resolver and specify the necessary credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
System.Net.NetworkCredential myCred;
myCred  = new System.Net.NetworkCredential(UserName,SecurelyStoredPassword,Domain);  
resolver.Credentials = myCred;


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker