CredentialCache.DefaultCredentials CredentialCache.DefaultCredentials CredentialCache.DefaultCredentials CredentialCache.DefaultCredentials Property

定義

アプリケーションのシステム資格情報を取得します。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

プロパティ値

アプリケーションのシステム資格情報を表す ICredentialsAn ICredentials that represents the system credentials of the application.

次のコード例では、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")

注釈

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.

注意

ICredentialsによって返されるインスタンスDefaultCredentialsユーザー名、パスワード、または現在のセキュリティ コンテキストのドメインを表示するのには使用できません。The ICredentials instance returned by DefaultCredentials cannot be used to view the user name, password, or domain of the current security context.

セキュリティ

EnvironmentPermission
ユーザー名の環境変数を読み取っています。for reading the USERNAME environment variable. 関連付けられた列挙体。 ReadAssociated enumeration: Read

適用対象