Click here to Skip to main content
6,596,602 members and growing! (19,913 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

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

By Ramana. G.V

Article explains How to get windows user name using ASP.NET
Windows, .NET, ASP.NET, Visual Studio, Dev
Posted:4 Jan 2006
Views:135,988
Bookmarked:30 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
31 votes for this article.
Popularity: 4.11 Rating: 2.75 out of 5
13 votes, 41.9%
1
1 vote, 3.2%
2
2 votes, 6.5%
3
3 votes, 9.7%
4
12 votes, 38.7%
5

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

About the Author

Ramana. G.V


Member
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.
Occupation: Software Developer (Senior)
Company: Wipro Technologies, pune
Location: India India

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 18 of 18 (Total in Forum: 18) (Refresh)FirstPrevNext
GeneralHow about this for ASP .NET PinmemberRTS@Orix7:10 28 May '09  
Generaltanks PinmemberMyLoveSarah2:44 16 Mar '09  
GeneralRe: tanks Pinmemberenvador9:30 5 May '09  
RantThis aticle makes no sense Pinmembersada.narayanappa17:39 24 Feb '09  
QuestionHow to Get Window NT Logged User Name Using ASP.NET Pinmemberhkim_zoro15:54 6 Feb '09  
GeneralMy vote of 1 PinmemberVlad Iliescu6:58 27 Jan '09  
QuestionI Keep getting ASP.NET Machine Account Pinmemberstout279:50 16 Sep '08  
GeneralVB Solution PinmemberTrissa11:11 14 Jun '07  
QuestionRe:C# Solution Pinmembertaweel3:48 15 Mar '09  
GeneralAnother quicker way to get the Identity PinmemberRaghu Nadh21:41 30 Apr '07  
GeneralRe: Another quicker way to get the Identity PinmemberArabisoft10:14 31 May '07  
GeneralRe: Another quicker way to get the Identity Pinmemberjoelperez8:55 19 Mar '08  
GeneralRe: Another quicker way to get the Identity Pinmembermycsharpcorner19:54 28 Nov '08  
Generalrequest.servervariables("remote_user") Pinmemberfdsilva5:50 3 Mar '06  
GeneralRe: request.servervariables("remote_user") PinmemberMalayil alex2:39 21 Mar '07  
GeneralRe: request.servervariables("remote_user") Pinmemberinthelight7:05 31 May '07  
GeneralA question about security Pinmemberusawnani9:44 10 Feb '06  
GeneralToString Pinmembersmallguy786:33 27 Jan '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 4 Jan 2006
Editor:
Copyright 2006 by Ramana. G.V
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project