Re: Get Windows User Name via ASP.NET

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Greg" <AccessVBAnet@xxxxxxxxxxxxxxxxx> wrote in message news:E688E391-FB19-4212-9445-F108621755CF@xxxxxxxxxxxxxxxx
[...]
WindowsIdentity.GetCurrent().Name.LastIndexOf(@"\") + 1);
[...]
But, once I move my web-site aspx files to the web server it returns
"NETWORK SERVICE" all the time.
[...] What am I doing wrong?

You are getting the identity of the process that is executing the code. If this is the code-behind in an asp.net web page, this defaults to the identity of the asp.net worker process, NOT the user that sits behind the brwser that requested the page.

And, how can I get the current Windows User Name for the computer requesting
the web page?

First, enable Integrated Windows Authentication in IIS. Second, set the <authorization> section in web.config so that anonymous access is denied for the page where you are trying to find the identity of the user. Third, verify that <authentication> is set to mode="windows". Then, you can get the identity of the windows user by means of:

string username = User.Identity.Name;

This only works for users that are browsing by means of Internet Explorer inside the local intranet. Other browsers do not support Integrated Windows Authentication. Internet Explorer defaults to not sending the user identity if the server is not in the local intranet (but this can be reconfigured).


.



Relevant Pages

  • Re: HELP
    ... First, I don't use MS Internet Explorer 6, except for the Windows Update ... My main browser is Mozilla 1.7.1. ... I could use a local web server and the 'hosts' ... tracking cookies; and if you look at the domain name for the cookie, ...
    (microsoft.public.security)
  • Integrated Authentication
    ... I'm having a problem with a web app that requires integrated authentication. ... Addresses without periods are considered to be on the intranet; Internet Explorer passes credentials automatically. ... This is apparently not true because in my test environment the web server is in the local domain but the url I type is a normal internet address for which I have and entry in my local hosts file to map the name to a local IP address. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: [OT] New worm attacks
    ... > IIS servers. ... It puts a piece of code on web pages and then infects PCs ... > that use Internet Explorer to access the web server. ...
    (Fedora)
  • Re: Stumped by Authentication Problem
    ... Administrator group on the Web server and I can't figure out why. ... We have a local group called Users that conains our Domain Users. ... - Integrated Windows Authentication ...
    (microsoft.public.inetserver.iis.security)
  • Re: Stumped by Authentication Problem
    ... Administrator group on the Web server and I can't figure out why. ... We have a local group called Users that conains our Domain Users. ... - Integrated Windows Authentication ...
    (microsoft.public.inetserver.iis.security)