ASP.NET C# How to get the windows login name or domain username?

How to get the windows login name or domain username?
mawinghoAsked:
Who is Participating?
 
PJBXCommented:
Have you tried: Context.User.Identity.Name


0
 
PagodNaUtakCommented:
Try the below code
string networklogon = null;
Array arrnetworklogon = null;
string loginname = null;

//get network user data
networklogon = Request.ServerVariables("LOGON_USER");
arrnetworklogon = Strings.Split(networklogon, "\\");
loginname = arrnetworklogon(Information.UBound(arrnetworklogon));

Open in new window

0
 
aternexCommented:
As long as the asp.net site is running windows authentication user.identity.name has always worked for me. This would return the username in the form of Domain\User
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
s_chilkuryCommented:
this.Context.User.Identity.Name;

will server the purpose.

Check the following:
http://weblogs.asp.net/jpinquie/archive/2008/02/06/how-to-get-domain-user-information-from-active-directory-in-c.aspx
0
 
mawinghoAuthor Commented:
It doesn't work
0
 
mawinghoAuthor Commented:
How to do windows authentication ???
am I need to add any code or change any setting?
I am using Microsoft Visual Web Developer 2010 Express.
and creating website
0
 
Asim NazirCommented:
0
 
MajorBigDealCommented:
Try this:

Inside the webpage:

Validate(HttpContext.Current);


In your other class (if you have one):

public void Validate(HttpContext currentContext)
{
   string name = currentContext.Request.LogonUserIdentity.Name;
   string isAuth = currentContext.Request.IsAuthenticated;
}
0
 
HSIHSACommented:
0
 
mawinghoAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.