Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / October 2006

Tip: Looking for answers? Try searching our database.

ICredentials questions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Thielen - 16 Oct 2006 00:56 GMT
Hi;

Four questions on credentials. These are all in a test Windows console app.
This is testing opening both \\server\share\file and
http://www.domain.com/file.

1) CredentialCache.DefaultCredentials and
CredentialCache.DefaultNetworkCredentials show a Username of "". Shouldn't
they be my username?
2) What user (if any) should new NetworkCredential() be?
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?
4) Is there a way to open as an anon user?

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

"Peter Huang" [MSFT] - 16 Oct 2006 05:00 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.