CredentialCache.DefaultCredentials Property

Definition

Возвращает системные учетные данные приложения.Gets the system credentials of the application.

public:
 static property System::Net::ICredentials ^ DefaultCredentials { System::Net::ICredentials ^ get(); };
public static System.Net.ICredentials DefaultCredentials { get; }
member this.DefaultCredentials : System.Net.ICredentials
Public Shared ReadOnly Property DefaultCredentials As ICredentials

Property Value

ICredentials

Значение ICredentials, которое представляет системные учетные данные приложения.An ICredentials that represents the system credentials of the application.

Examples

В следующем примере кода используется свойство DefaultCredentials для получения системных учетных данных приложения.The following code example uses the DefaultCredentials property to get the system credentials of the application.

// Ensure Directory Security settings for default web site in IIS is "Windows Authentication".
String^ url = "http://localhost";

// Create a 'HttpWebRequest' object with the specified url.
HttpWebRequest^ myHttpWebRequest = dynamic_cast<HttpWebRequest^>(WebRequest::Create( url ));

// Assign the credentials of the logged in user or the user being impersonated.
myHttpWebRequest->Credentials = CredentialCache::DefaultCredentials;

// Send the 'HttpWebRequest' and wait for response.
HttpWebResponse^ myHttpWebResponse = dynamic_cast<HttpWebResponse^>(myHttpWebRequest->GetResponse());
Console::WriteLine( "Authentication successful" );
Console::WriteLine( "Response received successfully" );

// Ensure Directory Security settings for default web site in IIS is "Windows Authentication".
string url = "http://localhost";
// Create a 'HttpWebRequest' object with the specified url.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
// Assign the credentials of the logged in user or the user being impersonated.
myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials;
// Send the 'HttpWebRequest' and wait for response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Console.WriteLine("Authentication successful");
Console.WriteLine("Response received successfully");
' Assuming "Windows Authentication" has been set as; 
' Directory Security settings for default web site in IIS.
Dim url As String = "http://localhost"
' Create a 'HttpWebRequest' object with the specified url. 
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
' Assign the credentials of the logged in user or the user being impersonated.
myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials
' Send the 'HttpWebRequest' and wait for response.            
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Console.WriteLine("Authentication successful")
Console.WriteLine("Response received successfully")

Remarks

Свойство DefaultCredentials применяется только к проверкам подлинности NTLM, Negotiate и Kerberos.The DefaultCredentials property applies only to NTLM, negotiate, and Kerberos-based authentication.

DefaultCredentials представляет системные учетные данные для текущего контекста безопасности, в котором выполняется приложение.DefaultCredentials represents the system credentials for the current security context in which the application is running. Для клиентского приложения обычно это учетные данные Windows (имя пользователя, пароль и домен) пользователя, запустившего приложение.For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. Для приложений ASP.NET учетные данные по умолчанию — это учетные данные пользователя, выполнившего вход в систему, или олицетворенного пользователя.For ASP.NET applications, the default credentials are the user credentials of the logged-in user, or the user being impersonated.

Чтобы получить учетные данные в качестве NetworkCredential экземпляра, используйте свойство DefaultNetworkCredentials.To get the credentials as a NetworkCredential instance, use the DefaultNetworkCredentials property.

Поддерживаемые значения для authType: "NTLM", "Digest", "Kerberos" и "Negotiate".The supported values for authType are "NTLM", "Digest", "Kerberos", and "Negotiate". Этот метод не работает для протоколов HTTP и FTP.This method does not work for HTTP or FTP protocols.

Note

Экземпляр ICredentials, возвращенный DefaultCredentials, нельзя использовать для просмотра имени пользователя, пароля или домена текущего контекста безопасности.The ICredentials instance returned by DefaultCredentials cannot be used to view the user name, password, or domain of the current security context.

Applies to