CredentialCache.DefaultCredentials プロパティ
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
アプリケーションのシステム資格情報を取得します。
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
アプリケーションのシステム資格情報を表す ICredentials。
次のコード例では、 プロパティを 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")
プロパティは DefaultCredentials 、NTLM、ネゴシエート、Kerberos ベースの認証にのみ適用されます。
DefaultCredentials は、アプリケーションが実行されている現在のセキュリティ コンテキストのシステム資格情報を表します。 クライアント側アプリケーションの場合、これらは通常、アプリケーションを実行しているユーザーの Windows 資格情報 (ユーザー名、パスワード、ドメイン) です。 ASP.NET アプリケーションの場合、既定の資格情報は、ログインしているユーザーのユーザー資格情報、または偽装されているユーザーです。
資格情報をインスタンスとして NetworkCredential 取得するには、 プロパティを DefaultNetworkCredentials 使用します。
でサポートされている値 authType
は、"NTLM"、"Digest"、"Kerberos"、"Negotiate" です。 このメソッドは、HTTP プロトコルまたは FTP プロトコルでは機能しません。
注意
ICredentialsによってDefaultCredentials返されるインスタンスを使用して、現在のセキュリティ コンテキストのユーザー名、パスワード、またはドメインを表示することはできません。
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。