WebClient.UseDefaultCredentials プロパティ

定義

Boolean が要求と共に送信されるかどうかを制御する DefaultCredentials 値を取得または設定します。

public:
 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

プロパティ値

Boolean

既定の資格情報を使用する場合は true。それ以外の場合は false。 既定値は false です。

次のコード例は、このプロパティの設定を示しています。

// 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 オブジェクトによって行われた要求がサーバーによって要求された場合に、現在ログオンしているユーザーの既定の資格情報を使用して認証する必要がある場合に設定します。 クライアント アプリケーションの場合、これはほとんどのシナリオで必要な動作です。 このプロパティを使用する代わりに、ASP.NET アプリケーションなどの中間層アプリケーションでは、通常、要求が行われるクライアントの資格情報にプロパティを設定Credentialsします。

適用対象