CredentialCache.DefaultCredentials Propiedad

Definición

Obtiene las credenciales de sistema de la aplicación.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

Valor de propiedad

ICredentials que representa las credenciales de sistema de la aplicación.An ICredentials that represents the system credentials of the application.

Ejemplos

En el ejemplo de código siguiente se usa la propiedad DefaultCredentials para obtener las credenciales del sistema de la aplicación.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")

Comentarios

La propiedad DefaultCredentials se aplica solo a la autenticación NTLM, Negotiate y basada en Kerberos.The DefaultCredentials property applies only to NTLM, negotiate, and Kerberos-based authentication.

DefaultCredentials representa las credenciales del sistema para el contexto de seguridad actual en el que se ejecuta la aplicación.DefaultCredentials represents the system credentials for the current security context in which the application is running. En el caso de una aplicación del lado cliente, suelen ser las credenciales de Windows (nombre de usuario, contraseña y dominio) del usuario que ejecuta la aplicación.For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. En el caso de las aplicaciones de ASP.NET, las credenciales predeterminadas son las credenciales de usuario del usuario que ha iniciado sesión o el usuario que se va a suplantar.For ASP.NET applications, the default credentials are the user credentials of the logged-in user, or the user being impersonated.

Para obtener las credenciales como una instancia de NetworkCredential, utilice la propiedad DefaultNetworkCredentials.To get the credentials as a NetworkCredential instance, use the DefaultNetworkCredentials property.

Los valores admitidos para authType son "NTLM", "Digest", "Kerberos" y "Negotiate".The supported values for authType are "NTLM", "Digest", "Kerberos", and "Negotiate". Este método no funciona para los protocolos HTTP o FTP.This method does not work for HTTP or FTP protocols.

Nota

No se puede usar la instancia de ICredentials devuelta por DefaultCredentials para ver el nombre de usuario, la contraseña o el dominio del contexto de seguridad actual.The ICredentials instance returned by DefaultCredentials cannot be used to view the user name, password, or domain of the current security context.

Se aplica a