Retrieving the web user's username in a domain

travisowens

Centurion
Joined
Feb 11, 2004
Messages
108
Location
Rochester, NY
I'm in an intranet/Windows domain setup on Windows 2003 and IIS6 coding an ASP.Net 1.1 Intranet application.

I need to retrieve the currnet web viewer's username (as authorized by the domain) but cannot seem to retrieve it anywhere. I notice products like MS Sharpeoint 2003 knows the username with a user typing it in. How can I get the username, I have tried the following ways below and as you can see, I always end up getting the username the ASP.Net is running as.

System.Security.Principal.WindowsIdentity.GetCurrent().Name: NT AUTHORITY\NETWORK SERVICE
System.Threading.Thread.CurrentPrincipal.Identity.Name:
System.Threading.Thread.CurrentThread.Name:
System.Windows.Forms.SystemInformation.UserName: NETWORK SERVICE
 
From within the ASP.Net application itself you should be able to use the user class to find out this info
Visual Basic:
label1.text = user.Identity.Name
label2.text = user.IsInRole("DOMAIN\Users")
 
Here is an answer

You'll have to refuse anonymous login to your app. And activate Domain Login by Basic or Digest (or anything...)

And activate Integrated Security. After that :

C#:
ntlogin = HttpContext.Current.User.Identity.Name; //Format : DOMAIN\USERNAME
ntlogin = zcntlogin.Substring( zcntlogin.IndexOf(@"\")+1);//FORMAT : USERNAME
Visual Basic:
ntlogin = HttpContext.Current.User.Identity.Name 'Format : DOMAIN\USERNAME
ntlogin = zcntlogin.Substring((zcntlogin.IndexOf("\") + 1)) 'Format: USERNAME
 
I GOT IT!

Ok I figured out why I never got the real username. I had to manage IIS, right click Web sites > Properties > Directory Security > Auth & Access Control EDIT
and then uncheck "enable anonymous acces"

I assumed IIS6 went from most secure to least secure ways to authorize, and figured anon would be last. It seems I was almast right, but anon comes first.

I can get the username in these parts of the framework:
User.Identity.Name
HttpContext.Current.User.Identity.Name
System.Threading.Thread.CurrentPrincipal.Identity.Name

And will be using the 1st or 2nd.
 
PlausiblyDamp,

it seems you were on to my problem, although you posted your question just 2 minutes after I figured it out. Big thanks for trying to help, this is something that has been nagging me for 2 weeks and I've just been working around it. This post helped me 'get in the mood' for try all sorts of things.
 
LOL

Exactly... but hey... who listen to my post ? :p

They are too lazy to scroll down :p lollll

Anyway... the answer is there... I can only show you the door. You'll have to open it yourself. :p (Quote from : Morpheus)
 
Back
Top