Provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication.
public ref class NetworkCredential : System::Net::ICredentials, System::Net::ICredentialsByHost
public ref class NetworkCredential : System::Net::ICredentials
public class NetworkCredential : System.Net.ICredentials, System.Net.ICredentialsByHost
public class NetworkCredential : System.Net.ICredentials
type NetworkCredential = class
interface ICredentials
interface ICredentialsByHost
type NetworkCredential = class
interface ICredentials
Public Class NetworkCredential
Implements ICredentials, ICredentialsByHost
Public Class NetworkCredential
Implements ICredentials
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 HttpClient 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("http://www.contoso.com"), "Basic", myCred);
myCache.Add(new Uri("http://app.contoso.com"), "Basic", myCred);
// HttpClient lifecycle management best practices:
// https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
HttpClient client = new HttpClient(new HttpClientHandler
{
Credentials = myCache
});
Dim myCred As New NetworkCredential(SecurelyStoredUserName, SecurelyStoredPassword, SecurelyStoredDomain)
Dim myCache As New CredentialCache()
myCache.Add(New Uri("http://www.contoso.com"), "Basic", myCred)
myCache.Add(New Uri("http://app.contoso.com"), "Basic", myCred)
' HttpClient lifecycle management best practices:
' https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
Dim client As New HttpClient(New HttpClientHandler With
{
.Credentials = myCache
})
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.
Note
On Unix platforms, use of NTLM authentication may require installing the NTLM plugin for the GSSAPI layer used by the implemention. On Ubuntu distributions, the package is called gss-ntlmssp
. Alternatively, applications may opt in for a managed implementation of NTLM by setting the _UseManagedNtlm
.csproj property (.NET 9+ only), or setting the System.Net.Security.UseManagedNtlm
AppContext switch.
On Windows, NTLM and Negotiate (Kerberos) authentication always depend on GSSAPI of the operating system.
This class does not support public key-based authentication methods such as Secure Sockets Layer (SSL) client authentication.
Constructors NetworkCredential()Initializes a new instance of the NetworkCredential class.
NetworkCredential(String, SecureString, String)Initializes a new instance of the NetworkCredential class with the specified user name, password, and domain.
NetworkCredential(String, SecureString)Initializes a new instance of the NetworkCredential class with the specified user name and password.
NetworkCredential(String, String, String)Initializes a new instance of the NetworkCredential class with the specified user name, password, and domain.
NetworkCredential(String, String)Initializes a new instance of the NetworkCredential class with the specified user name and password.
Properties DomainGets or sets the domain or computer name that verifies the credentials.
PasswordGets or sets the password for the user name associated with the credentials.
SecurePasswordGets or sets the password as a SecureString instance.
UserNameGets or sets the user name associated with the credentials.
MethodsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4