Re: Get Windows User Name via ASP.NET
- From: "Alberto Poblacion" <earthling-quitaestoparacontestar@xxxxxxxxxxxxx>
- Date: Thu, 30 Apr 2009 20:32:16 +0200
"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).
.
- Follow-Ups:
- Re: Get Windows User Name via ASP.NET
- From: Jesse Houwing
- Re: Get Windows User Name via ASP.NET
- References:
- Get Windows User Name via ASP.NET
- From: Greg
- Get Windows User Name via ASP.NET
- Prev by Date: Re: What is the equivalent to the namespace My from VB in c#?
- Next by Date: Re: when I add a new class to the project, all the other goes wron
- Previous by thread: Get Windows User Name via ASP.NET
- Next by thread: Re: Get Windows User Name via ASP.NET
- Index(es):
Relevant Pages
|