Username in Web-App

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How would I get the current username using C# in an .ASPX web-app? I tried
System.Security.Principal.WindowsIdentity.GetCurrent().Name and this returns
'NT AUTHORITY\SYSTEM' I also tried System.Environment.UserName which just
returns 'SYSTEM'

What am I missing, or what should I do to get this to work?

Thanks
Andy
 
Hi,

You should disable the anonymous access from IIS config applet and make
sure that the Integrated windows auth is checked

then set this in the web.config file

<authentication mode="Windows"/>
<identity impersonate="true"/>

with that you can access the user from your code using

WindowsIdentity.GetCurrent().Name


Cheers,
 
Nicole:

Thank you very much. This helped a lot. I was missing the impersonate
value in my web.config file.
 
Back
Top