
Signature
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
Cubicle Wars - http://www.windwardreports.com/film.htm
Hi David,
Here the discussion is based on Windows Application.
| 1) CredentialCache.DefaultCredentials and
| CredentialCache.DefaultNetworkCredentials show a Username of "". Shouldn't
| they be my username?
Based on my research, in the MSDN it has a small note as below.
Note
The ICredentials instance returned by DefaultCredentials cannot be used to
view the user name, password, or domain of the current security context.
http://msdn2.microsoft.com/en-us/library/system.net.credentialcache.defaultc
redentials.aspx
In Windows application, you may use the method below to retrieve the
current running process's username.
Console.WriteLine(System.Environment.UserName);
| 2) What user (if any) should new NetworkCredential() be?
Commonly I think they has minor different. Also if we take a look at the
reflection code of the two properties, we will find that they are running
the same code.
public static ICredentials DefaultCredentials
{
get
{
new EnvironmentPermission(EnvironmentPermissionAccess.Read,
"USERNAME").Demand();
return SystemNetworkCredential.defaultCredential;
}
}
public static NetworkCredential DefaultNetworkCredentials
{
get
{
new EnvironmentPermission(EnvironmentPermissionAccess.Read,
"USERNAME").Demand();
return SystemNetworkCredential.defaultCredential;
}
}
| 3) If I don't open with credentials it uses the credentials of the current
| user - correct? And if I am impersonating a user, it uses that user - correct?
YES, if we run a windows application it will be running under certain
account, which is commonly the logon user. Once we impersonate the current
process in another user account, e.g. call the LogonUser API, which will be
running the current code in the user being called LogonUser.
| 4) Is there a way to open as an anon user?
Yes, we can use the LogonUser API to do impersonate issue.
Windows Impersonation using C#
http://www.codeproject.com/csharp/cpimpersonation1.asp
If you have any concern, please feel free to let me know.
Best regards,
Peter Huang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.