Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
DefaultCredentials Property
Collapse the table of content
Expand the table of content

CredentialCache.DefaultCredentials Property

Gets the system credentials of the application.

Namespace:  System.Net
Assemblies:   System (in System.dll)
  System.Net.Primitives (in System.Net.Primitives.dll)

'Declaration
Public Shared ReadOnly Property DefaultCredentials As ICredentials

Property Value

Type: System.Net.ICredentials
An ICredentials that represents the system credentials of the application.

The DefaultCredentials property applies only to NTLM, negotiate, and Kerberos-based authentication.

DefaultCredentials represents the system credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default credentials are the user credentials of the logged-in user, or the user being impersonated.

To get the credentials as a NetworkCredential instance, use the DefaultNetworkCredentials property.

The supported values for authType are "NTLM", "Digest", "Kerberos", and "Negotiate". This method does not work for HTTP or FTP protocols.

NoteNote

The ICredentials instance returned by DefaultCredentials cannot be used to view the user name, password, or domain of the current security context.

The following code example uses the DefaultCredentials property to get the system credentials of the application.

' Assuming "Windows Authentication" has been set as;  
' Directory Security settings for default web site in IIS. 
Dim url As String = "http://localhost" 
' Create a 'HttpWebRequest' object with the specified url.  
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
' Assign the credentials of the logged in user or the user being impersonated.
myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials
' Send the 'HttpWebRequest' and wait for response.             
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Console.WriteLine("Authentication successful")
Console.WriteLine("Response received successfully")

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8

Show:
© 2015 Microsoft