WebClient.UseDefaultCredentials 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 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
屬性值
如果使用預設認證,則為 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 為代表要求之用戶端的認證。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應