Click here to Skip to main content
Click here to Skip to main content

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

, 4 Jan 2006
Rate this:
Please Sign up or sign in to vote.
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;

string strName = p.Identity.Name;

[ 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

In Above 3 Cases returnin string contains DomainName\WinNTLoggedUserName

(for Ex: Microsoft\Bill.Gates. Here Microsoft is domain Bill.Gates is Logger User Name )

Using string operations seperate the DomainName and UserName.

 
 


 

 

 

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

Share

About the Author

Ramana.Gali
Technical Lead
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 PinmemberRajamohan.Rajendran1-Jun-11 18:31 
Generalget windows nt logged user name PinmemberMember 324702231-Dec-10 2:18 
GeneralMy vote of 1 Pinmemberdivyesh143219-Mar-10 22:43 
GeneralRe: My vote of 1 [modified] Pinmembermandelbrot197010-May-12 4:36 
GeneralMy vote of 1 PinmemberRaghavan Ram Raja15-Mar-10 4:07 
QuestionHow about this for ASP .NET PinmemberRTS@Orix28-May-09 6:10 
Generaltanks PinmemberMyLoveSarah16-Mar-09 1:44 
GeneralRe: tanks Pinmemberenvador5-May-09 8:30 
RantThis aticle makes no sense Pinmembersada.narayanappa124-Feb-09 6:39 
QuestionHow to Get Window NT Logged User Name Using ASP.NET Pinmemberhkim_zoro6-Feb-09 14:54 
GeneralMy vote of 1 PinmemberVlad Iliescu27-Jan-09 5:58 
QuestionI Keep getting ASP.NET Machine Account Pinmemberstout2716-Sep-08 8:50 
GeneralVB Solution PinmemberTrissa14-Jun-07 10:11 
QuestionRe:C# Solution Pinmembertaweel15-Mar-09 2:48 
GeneralAnother quicker way to get the Identity PinmemberRaghu Nadh30-Apr-07 20:41 
GeneralRe: Another quicker way to get the Identity PinmemberArabisoft31-May-07 9:14 
This doesn't work in web pages. If you try this in a web page it will return NT Authority\Network Service even if your site disallows anonymous. The surefire method for me is Request.ServerVariables("AUTH_USER") or [] for C#.
GeneralRe: Another quicker way to get the Identity Pinmemberjoelperez19-Mar-08 7:55 
GeneralRe: Another quicker way to get the Identity Pinmembermycsharpcorner28-Nov-08 18:54 
Generalrequest.servervariables("remote_user") Pinmemberfdsilva3-Mar-06 4:50 
GeneralRe: request.servervariables("remote_user") PinmemberMalayil alex21-Mar-07 1:39 
GeneralRe: request.servervariables("remote_user") Pinmemberinthelight31-May-07 6:05 
GeneralA question about security Pinmemberusawnani10-Feb-06 8:44 
GeneralToString Pinmembersmallguy7827-Jan-06 5:33 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 4 Jan 2006
Article Copyright 2006 by Ramana.Gali
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid