アプリケーションのシステム資格情報を取得します。
Public Shared ReadOnly Property DefaultCredentials As ICredentials
[C#]
public static ICredentials DefaultCredentials {get;}
[C++]
public: __property static ICredentials* get_DefaultCredentials();
[JScript]
public static function get DefaultCredentials() : ICredentials;
プロパティ値
アプリケーションのシステム資格情報を表す ICredentials 。
解説
DefaultCredentials プロパティは、NTLM 認証、ネゴシエート認証、および Kerberos ベースの認証だけに適用されます。
DefaultCredentials は、アプリケーションが実行されている現在のセキュリティ コンテキストのシステム資格情報を表します。クライアント側アプリケーションでは、通常、アプリケーションを実行しているユーザーの Windows 資格情報 (ユーザー名、パスワード、およびドメイン) です。ASP.NET アプリケーションでは、既定の資格情報は、ログインしているユーザーまたは偽装されているユーザーのユーザー資格情報です。
メモ DefaultCredentials によって返される ICredentials インスタンスは、現在のセキュリティ コンテキストのユーザー名、パスワード、またはドメインを表示するためには使用できません。
使用例
[Visual Basic, C#, C++] DefaultCredentials メソッドを使用して、アプリケーションのシステム資格情報を取得する例を次に示します。
' Assuming "Windows Authentication" has been set as;
' Directory Security settings for default web site in IIS.
Dim url As String = "https://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")
[C#]
// Ensure Directory Security settings for default web site in IIS is "Windows Authentication".
string url = "https://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");
[C++]
// Ensure Directory Security settings for default web site in IIS is S"Windows Authentication".
String* url = S"https://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(S"Authentication successful");
Console::WriteLine(S"Response received successfully");
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard
.NET Framework セキュリティ:
- EnvironmentPermission (ユーザーのシステム資格情報を読み取るために必要なアクセス許可) EnvironmentPermissionAccess (関連する列挙体)