System.Net.NetworkCredential Class

Assembly: System.dll
Namespace: System.Net
Summary
Provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication.
C# Syntax:
public class NetworkCredential : ICredentials
Remarks
The NetworkCredential class is a base class that supplies credentials in password-based authentication schemes such as basic, digest, NTLM, and Kerberos. Classes that implement the ICredentials interface, such as the CredentialCache class, return NetworkCredential instances.

This class does not support public key-based authentication methods such as SSL client authentication.

Example
The following example associates a NetworkCredential instance with a set of Uniform Resource Identifiers (URIs) in a CredentialCache. It then passes the CredentialCache to a WebRequest instance, which uses it to authenticate requests to an Internet server.
NetworkCredential myCred = new NetworkCredential("username","password","domain");
 
CredentialCache myCache = new CredentialCache();
 
myCache.Add(new Uri("www.contoso.com"), "Basic", myCred);
myCache.Add(new Uri("app.contoso.com"), "Basic", myCred);
 
WebRequest wr = WebRequest.Create("www.contoso.com");
wr.Credentials = myCache;


    
See also:
System.Net Namespace

System.Net.NetworkCredential Member List:

Public Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the NetworkCredential class.
ctor #2 Overloaded:
.ctor(string userName, string password)

Initializes a new instance of the NetworkCredential class with the specified user name and password.
ctor #3 Overloaded:
.ctor(string userName, string password, string domain)

Initializes a new instance of the NetworkCredential class with the specified user name, password, and domain.
Public Properties
Domain Read-write

Gets or sets the domain or computer name that verifies the credentials.
Password Read-write

Gets or sets the password for the user name associated with the credentials.
UserName Read-write

Gets or sets the user name associated with the credentials.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetCredential Returns an instance of the NetworkCredential class for the specified URI and authentication type.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Net.NetworkCredential Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the NetworkCredential class.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public NetworkCredential();
Remarks
The default constructor for the NetworkCredential class initailizes all properties to null.

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the NetworkCredential class with the specified user name and password.
C# Syntax:
public NetworkCredential(
   string userName,
   string password
);
Parameters:

userName

The user name associated with the credentials.

password

The password for the user name associated with the credentials.

Remarks
The constructor initializes a NetworkCredential instance is initialized with the NetworkCredential.UserName property set to userName and the NetworkCredential.Password property set to password.

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of the NetworkCredential class with the specified user name, password, and domain.
C# Syntax:
public NetworkCredential(
   string userName,
   string password,
   string domain
);
Parameters:

userName

The user name associated with the credentials.

password

The password for the user name associated with the credentials.

domain

The domain associated with these credentials.

Remarks
The constructor initializes a NetworkCredential instance with the NetworkCredential.UserName property set to userName, the NetworkCredential.Password property set to password, and the NetworkCredential.Domain property set to domain.

Return to top


Property: Domain (read-write)
Summary
Gets or sets the domain or computer name that verifies the credentials.
C# Syntax:
public string Domain {get; set;}
Remarks
The NetworkCredential.Domain property specifies the domain or realm to which the user name belongs. Typically, this is the host computer name where the application runs or user domain for the currently logged in user.
.NET Framework Security:
EnvironmentPermission to get the system domain. Associated enumeration: EnvironmentPermissionAccess.Read

Return to top


Property: Password (read-write)
Summary
Gets or sets the password for the user name associated with the credentials.
C# Syntax:
public string Password {get; set;}
.NET Framework Security:
SecurityPermission to get the user password. Associated enumeration: SecurityPermissionFlag.UnmanagedCode

Return to top


Property: UserName (read-write)
Summary
Gets or sets the user name associated with the credentials.
C# Syntax:
public string UserName {get; set;}
.NET Framework Security:
EnvironmentPermission to read the user name from the system. Associated enumeration: EnvironmentPermissionAccess.Read

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~NetworkCredential();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetCredential(
   Uri uri,
   string authType
)
Summary
Returns an instance of the NetworkCredential class for the specified URI and authentication type.
C# Syntax:
public NetworkCredential GetCredential(
   Uri uri,
   string authType
);
Parameters:

uri

The URI that the client is providing authentication for.

authType

The type of authentication requested as defined in the IAuthenticationModule.AuthenticationType property.

Return Value:
A NetworkCredential instance.
Implements:
ICredentials.GetCredential

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.