WebClient.UseDefaultCredentials WebClient.UseDefaultCredentials WebClient.UseDefaultCredentials WebClient.UseDefaultCredentials Property

Definition

Ruft einen Boolean-Wert ab, der steuert, ob mit den Anforderungen DefaultCredentials gesendet werden, oder legt diesen fest.Gets or sets a Boolean value that controls whether the DefaultCredentials are sent with requests.

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

Eigenschaftswert

true, wenn die Standardanmeldeinformationen verwendet werden, andernfalls false.true if the default credentials are used; otherwise false. Der Standardwert ist falsesein.The default value is false.

Beispiele

Das folgende Codebeispiel veranschaulicht das Festlegen dieser Eigenschaft.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

Hinweise

Legen Sie diese Eigenschaft auf true bei Anforderungen von dieser WebClient Objekt sollte, wenn vom Server angefordert authentifiziert werden mit den Standardanmeldeinformationen des aktuell angemeldeten Benutzers.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. Bei Clientanwendungen ist dies das gewünschte Verhalten in den meisten Szenarien.For client applications, this is the desired behavior in most scenarios. Für Anwendungen der mittleren Ebene, z. B. ASP.NET-Anwendungen anstelle dieser Eigenschaft legen Sie in der Regel die Credentials Eigenschaft, um die Anmeldeinformationen des Clients in deren Auftrag die Anforderung wird ausgeführt.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.

Gilt für: