NetworkCredential Class
Provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication.
Assembly: System (in System.dll)
The NetworkCredential type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() ![]() | NetworkCredential() | Initializes a new instance of the NetworkCredential class. |
![]() | NetworkCredential(String, SecureString) | Initializes a new instance of the NetworkCredential class with the specified user name and password. |
![]() ![]() ![]() | NetworkCredential(String, String) | Initializes a new instance of the NetworkCredential class with the specified user name and password. |
![]() | NetworkCredential(String, SecureString, String) | Initializes a new instance of the NetworkCredential class with the specified user name, password, and domain. |
![]() ![]() ![]() | NetworkCredential(String, String, String) | Initializes a new instance of the NetworkCredential class with the specified user name, password, and domain. |
| Name | Description | |
|---|---|---|
![]() ![]() ![]() | Domain | Gets or sets the domain or computer name that verifies the credentials. |
![]() ![]() ![]() | Password | Gets or sets the password for the user name associated with the credentials. |
![]() | SecurePassword | Gets or sets the password as a SecureString instance. |
![]() ![]() ![]() | UserName | Gets or sets the user name associated with the credentials. |
| Name | Description | |
|---|---|---|
![]() ![]() ![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() ![]() ![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() ![]() ![]() | GetCredential(Uri, String) | Returns an instance of the NetworkCredential class for the specified Uniform Resource Identifier (URI) and authentication type. |
![]() | GetCredential(String, Int32, String) | Returns an instance of the NetworkCredential class for the specified host, port, and authentication type. |
![]() ![]() ![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() ![]() ![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() ![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() ![]() ![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
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 objects.
This class does not support public key-based authentication methods such as Secure Sockets Layer (SSL) client authentication.
The following code example associates a NetworkCredential object with a set of Uniform Resource Identifiers (URIs) in a CredentialCache. It then passes the CredentialCache to a WebRequest object, which uses it to authenticate requests to an Internet server.
NetworkCredential myCred = new NetworkCredential( SecurelyStoredUserName,SecurelyStoredPassword,SecurelyStoredDomain); 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;
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.




