CredentialCache.DefaultCredentials Właściwość

Definicja

Pobiera poświadczenia systemowe aplikacji.

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

Wartość właściwości

Element ICredentials reprezentujący poświadczenia systemowe aplikacji.

Przykłady

Poniższy przykład kodu używa DefaultCredentials właściwości w celu uzyskania poświadczeń systemowych aplikacji.

// 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")

Uwagi

Właściwość DefaultCredentials dotyczy tylko uwierzytelniania NTLM, negocjowania i uwierzytelniania opartego na protokole Kerberos.

DefaultCredentials reprezentuje poświadczenia systemowe dla bieżącego kontekstu zabezpieczeń, w którym działa aplikacja. W przypadku aplikacji po stronie klienta są to zazwyczaj poświadczenia systemu Windows (nazwa użytkownika, hasło i domena) użytkownika z uruchomioną aplikacją. W przypadku aplikacji ASP.NET poświadczenia domyślne to poświadczenia użytkownika zalogowanego użytkownika lub personifikacja użytkownika.

Aby uzyskać poświadczenia jako NetworkCredential wystąpienie, użyj DefaultNetworkCredentials właściwości .

Obsługiwane wartości authType to "NTLM", "Digest", "Kerberos" i "Negotiate". Ta metoda nie działa w przypadku protokołów HTTP ani FTP.

Uwaga

Wystąpienie ICredentials zwrócone przez DefaultCredentials program nie może służyć do wyświetlania nazwy użytkownika, hasła lub domeny bieżącego kontekstu zabezpieczeń.

Dotyczy