Click here to Skip to main content
15,850,548 members
Articles / Web Development / ASP.NET
Article

How to Get Window NT Logged User Name Using ASP.NET

Rate me:
Please Sign up or sign in to vote.
2.81/5 (37 votes)
4 Jan 20061 min read 418.4K   43   23
Article explains How to get windows user name using ASP.NET

Introduction

This article shows How to get the Windows current logged user name using ASP.NET

First Step Setting  Up Web Server

To get the windows user name through programatically. Compulsary we need to set the web server.

Open the Internet Infomation Services(IIS), Select your ASP.NET Virtual Directory, right click, go to the Properties, In Properties window go to Directory Security Tab, Here You Find the "Edit" button in Anonymous access and Authentication Control. Press Edit Button. Now Authentication Methods dialogbox will appear.

In this dialog box by default it is set(checked) Anonymous Access. uncheck this checkbox and go to botom of this dialog box check the Integrated windows authentication. Here why we are selecting this Default web server is logged by ISUER_MachineName so if it is window authentication web server will take the credentials from windows logged user.

Getting the User Name :

using three ways we can get the User Name using C#

1) System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;</P>

<P>string strName = p.Identity.Name;</P>

[ OR ]

2) string strName = HttpContext.Current.User.Identity.Name.ToString();

[ OR ]

3) string strName = Request.ServerVariables["AUTH_USER"]; //Finding with name

    string strName = Request.ServerVariables[5]; //Finding with index</P>
<P>In Above 3 Cases returnin string contains DomainName\WinNTLoggedUserName </P>
<P>(for  Ex:  Microsoft\Bill.Gates. Here Microsoft is domain Bill.Gates is Logger User Name )</P>
<P>Using string operations seperate the DomainName and UserName. </P>
<P> </P>

 
 


 

 

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect
Singapore Singapore
C# Developer have Hands on Web Developement using ASP.NET, Web Services, Win Serivces, Pocket PC, Smart Device,Enterprize Security Applications and Win Forms Development using .NET FW 1.1 & 2.0.

Comments and Discussions

 
GeneralMy vote of 4 Pin
Rajamohan.Rajendran1-Jun-11 19:31
Rajamohan.Rajendran1-Jun-11 19:31 
Generalget windows nt logged user name Pin
Member 324702231-Dec-10 3:18
Member 324702231-Dec-10 3:18 
GeneralMy vote of 1 Pin
divyesh143219-Mar-10 23:43
divyesh143219-Mar-10 23:43 
GeneralRe: My vote of 1 Pin
P Weston10-May-12 5:36
P Weston10-May-12 5:36 
GeneralMy vote of 1 Pin
Rammohan Raja15-Mar-10 5:07
Rammohan Raja15-Mar-10 5:07 
QuestionHow about this for ASP .NET Pin
RTS@WORK28-May-09 7:10
RTS@WORK28-May-09 7:10 
Generaltanks Pin
IranianProgrammer16-Mar-09 2:44
IranianProgrammer16-Mar-09 2:44 
GeneralRe: tanks Pin
envador5-May-09 9:30
envador5-May-09 9:30 
RantThis aticle makes no sense Pin
sada.narayanappa124-Feb-09 7:39
sada.narayanappa124-Feb-09 7:39 
QuestionHow to Get Window NT Logged User Name Using ASP.NET Pin
hkim_zoro6-Feb-09 15:54
hkim_zoro6-Feb-09 15:54 
GeneralMy vote of 1 Pin
User 214775727-Jan-09 6:58
User 214775727-Jan-09 6:58 
QuestionI Keep getting ASP.NET Machine Account Pin
stout2716-Sep-08 9:50
stout2716-Sep-08 9:50 
GeneralVB Solution Pin
Trissa14-Jun-07 11:11
Trissa14-Jun-07 11:11 
QuestionRe:C# Solution Pin
taweel15-Mar-09 3:48
taweel15-Mar-09 3:48 
GeneralAnother quicker way to get the Identity Pin
Raghu Penumarthi30-Apr-07 21:41
professionalRaghu Penumarthi30-Apr-07 21:41 
GeneralRe: Another quicker way to get the Identity Pin
Arabisoft31-May-07 10:14
Arabisoft31-May-07 10:14 
GeneralRe: Another quicker way to get the Identity Pin
joelperez19-Mar-08 8:55
joelperez19-Mar-08 8:55 
GeneralRe: Another quicker way to get the Identity Pin
mycsharpcorner28-Nov-08 19:54
mycsharpcorner28-Nov-08 19:54 
Generalrequest.servervariables("remote_user") Pin
fdsilva3-Mar-06 5:50
fdsilva3-Mar-06 5:50 
GeneralRe: request.servervariables("remote_user") Pin
Malayil alex21-Mar-07 2:39
Malayil alex21-Mar-07 2:39 
GeneralRe: request.servervariables(&amp;amp;quot;remote_user&amp;amp;quot;) Pin
inthelight31-May-07 7:05
inthelight31-May-07 7:05 
GeneralA question about security Pin
krishnar789910-Feb-06 9:44
krishnar789910-Feb-06 9:44 
GeneralToString Pin
yetanotherchris27-Jan-06 6:33
yetanotherchris27-Jan-06 6:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.