CredentialCache.DefaultCredentials Özellik

Tanım

Uygulamanın sistem kimlik bilgilerini alır.

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

Özellik Değeri

ICredentials Uygulamanın sistem kimlik bilgilerini temsil eden bir.

Örnekler

Aşağıdaki kod örneği, uygulamanın sistem kimlik bilgilerini almak için özelliğini kullanır DefaultCredentials .

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

Açıklamalar

DefaultCredentials özelliği yalnızca NTLM, negotiate ve Kerberos tabanlı kimlik doğrulaması için geçerlidir.

DefaultCredentials , uygulamanın çalıştığı geçerli güvenlik bağlamı için sistem kimlik bilgilerini temsil eder. İstemci tarafı bir uygulama için bunlar genellikle uygulamayı çalıştıran kullanıcının Windows kimlik bilgileridir (kullanıcı adı, parola ve etki alanı). ASP.NET uygulamalar için, varsayılan kimlik bilgileri oturum açmış kullanıcının veya kimliğine bürünülen kullanıcının kullanıcı kimlik bilgileridir.

Kimlik bilgilerini örnek NetworkCredential olarak almak için özelliğini kullanın DefaultNetworkCredentials .

için authType desteklenen değerler "NTLM", "Digest", "Kerberos" ve "Negotiate" değerleridir. Bu yöntem HTTP veya FTP protokolleri için çalışmaz.

Not

ICredentials tarafından DefaultCredentials döndürülen örnek, geçerli güvenlik bağlamının kullanıcı adını, parolasını veya etki alanını görüntülemek için kullanılamaz.

Şunlara uygulanır