Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DefaultNetworkCredentials or DefaultCredentials

Which one am I supposed to use when I need to supply a credential to a proxy (local or in Network)?

What's the exact difference between these two?

like image 767
dr. evil Avatar asked Mar 27 '10 09:03

dr. evil


People also ask

What is DefaultNetworkCredentials?

The credentials returned by DefaultNetworkCredentials represents the authentication 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.

What is CredentialCache in C#?

The CredentialCache class stores credentials for multiple Internet resources. Applications that need to access multiple resources can store the credentials for those resources in a CredentialCache instance that then provides the proper set of credentials to the Internet resource when required.


2 Answers

They are exactly the same thing, which you can confirm for yourself using a disassembler like Reflector. The only difference is that DefaultNetworkCredentials returns a NetworkCredentials object and and DefaultCredentials casts it to ICredentials. So you have access to more information with a NetworkCredentials object, but which of those you use supply to an object requiring an ICredentials instance makes no difference, since it's the same object instance: object.ReferenceEquals(CredentialCache.DefaultCredentials, CredentialCache.DefaultNetworkCredentials) returns true.

like image 105
EMP Avatar answered Oct 22 '22 18:10

EMP


The difference between the two is very subtle. DefaultNetworkCredentials is the newer of the two (added with .NET 2.0), and the core difference is that under certain security conditions, it can expose more private information about the logged-in user to the application. For more information, try this blog post:

http://blogs.msdn.com/buckh/archive/2004/07/28/199706.aspx

like image 29
Dan Story Avatar answered Oct 22 '22 16:10

Dan Story