WebClient.UseDefaultCredentials プロパティ


Boolean が要求と共に送信されるかどうかを制御する DefaultCredentials 値を取得または設定します。Gets or sets a Boolean value that controls whether the DefaultCredentials are sent with requests.

 property bool UseDefaultCredentials { bool get(); void set(bool value); };
public bool UseDefaultCredentials { get; set; }
member this.UseDefaultCredentials : bool with get, set
Public Property UseDefaultCredentials As Boolean



既定の資格情報を使用する場合は true。それ以外の場合は falsetrue if the default credentials are used; otherwise false. 既定値は false です。The default value is false.

このプロパティを設定するコード例を次に示します。The following code example demonstrates setting this property.

// Sample call: UploadFileInBackground3("http://www.contoso.com/fileUpload.aspx", "data.txt")
void UploadFileInBackground3( String^ address, String^ fileName )

   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);

   client->UseDefaultCredentials = true;

   client->UploadFileCompleted += gcnew UploadFileCompletedEventHandler( UploadFileCallback2 );
   client->UploadFileAsync( uri, fileName );
   Console::WriteLine( "File upload started." );

// Sample call: UploadFileInBackground3("http://www.contoso.com/fileUpload.aspx", "data.txt")
public static void UploadFileInBackground3(string address, string fileName)
    WebClient client = new WebClient();

    Uri uri = new Uri(address);

    client.UseDefaultCredentials = true;
    client.UploadFileCompleted += new UploadFileCompletedEventHandler(UploadFileCallback2);
    client.UploadFileAsync(uri, fileName);
    Console.WriteLine("File upload started.");
'  Sample call: UploadFileInBackground3("http:' www.contoso.com/fileUpload.aspx", "data.txt")
Public Shared Sub UploadFileInBackground3(ByVal address As String, ByVal fileName As String)

    Dim client As WebClient = New WebClient()
                Dim uri as Uri =  New Uri(address)
    client.UseDefaultCredentials = True
    AddHandler client.UploadFileCompleted, AddressOf UploadFileCallback2
    client.UploadFileAsync(uri, fileName)
    Console.WriteLine("File upload started.")
End Sub


この true オブジェクトによる要求 WebClient が、サーバーから要求された場合に、現在ログオンしているユーザーの既定の資格情報を使用して認証されるようにするには、このプロパティをに設定します。Set this property to true when requests made by this WebClient object should, if requested by the server, be authenticated using the default credentials of the currently logged on user. クライアントアプリケーションの場合、これはほとんどのシナリオで望ましい動作です。For client applications, this is the desired behavior in most scenarios. ASP.NET アプリケーションなどの中間層アプリケーションでは、このプロパティを使用するのではなく、通常、 Credentials 要求の発行元のクライアントの資格情報にプロパティを設定します。For middle tier applications, such as ASP.NET applications, instead of using this property, you would typically set the Credentials property to the credentials of the client on whose behalf the request is made.