WebClient.UseDefaultCredentials Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Property Value
true
if the default credentials are used; otherwise false
. The default value is false
.
Examples
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
Remarks
Caution
WebRequest
, HttpWebRequest
, ServicePoint
, and WebClient
are obsolete, and you shouldn't use them for new development. Use HttpClient instead.
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. 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.