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?
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?
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:
They are exactly the same thing, which you can confirm for yourself using a disassembler like Reflector. The only difference is that
DefaultNetworkCredentials
returns aNetworkCredentials
object and andDefaultCredentials
casts it toICredentials
. 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)
returnstrue
.