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

Im folgenden Codebeispiel wird das Festlegen dieser Eigenschaft veranschaulicht.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 fest, wenn die von diesem WebClient-Objekt vorgenommenen Anforderungen vom Server mit den Standard Anmelde Informationen des aktuell angemeldeten Benutzers authentifiziert werden sollen.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 Client Anwendungen 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, legen Sie die Credentials-Eigenschaft in der Regel auf die Anmelde Informationen des Clients fest, für den die Anforderung erfolgt ist, anstatt diese Eigenschaft zu verwenden.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: