CredentialCache.DefaultCredentials プロパティ
アセンブリ: System (system.dll 内)

アプリケーションのシステム資格情報を表す ICredentials。

DefaultCredentials プロパティは、NTLM 認証、ネゴシエート認証、および Kerberos ベースの認証だけに適用されます。
DefaultCredentials は、アプリケーションが実行されている現在のセキュリティ コンテキストのシステム資格情報を表します。クライアント側アプリケーションでは、通常、アプリケーションを実行しているユーザーの Windows 資格情報 (ユーザー名、パスワード、およびドメイン) です。ASP.NET アプリケーションでは、既定の資格情報は、ログインしているユーザーまたは偽装されているユーザーのユーザー資格情報です。
資格情報を NetworkCredential インスタンスとして取得するには、DefaultNetworkCredentials プロパティを使用します。
authType に使用できる値は、"NTLM"、"Digest"、"Kerberos"、および "Negotiate" です。このメソッドは、HTTP プロトコルおよび FTP プロトコルでは動作しません。
![]() |
---|
DefaultCredentials によって返される ICredentials インスタンスは、現在のセキュリティ コンテキストのユーザー名、パスワード、またはドメインを表示するためには使用できません。 |

DefaultCredentials プロパティを使用して、アプリケーションのシステム資格情報を取得するコード例を次に示します。
' 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")
// 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");
// 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.set_Credentials(CredentialCache. get_DefaultCredentials()); // Send the 'HttpWebRequest' and wait for response. HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); Console.WriteLine("Authentication successful"); Console.WriteLine("Response received successfully");


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- CredentialCache.DefaultCredentials プロパティのページへのリンク