DefaultNetworkCredentials or DefaultCredentials

dr. evil picture dr. evil · Mar 27, 2010 · Viewed 13.7k times · Source

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?

Answer

EMP picture EMP · Mar 27, 2010

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.