Solved

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

Posted on 2011-02-14
10
1,385 Views
Last Modified: 2012-05-11
How to get the windows login name or domain username?
0
Comment
Question by:mawingho
10 Comments
 
LVL 6

Accepted Solution

by:
PJBX earned 72 total points
ID: 34893940
Have you tried: Context.User.Identity.Name


0
 
LVL 8

Assisted Solution

by:PagodNaUtak
PagodNaUtak earned 72 total points
ID: 34893955
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
 
LVL 5

Assisted Solution

by:aternex
aternex earned 72 total points
ID: 34894011
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Assisted Solution

by:s_chilkury
s_chilkury earned 71 total points
ID: 34894021
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
 

Author Comment

by:mawingho
ID: 34894044
It doesn't work
0
 

Author Comment

by:mawingho
ID: 34894053
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
 
LVL 10

Assisted Solution

by:Asim Nazir
Asim Nazir earned 71 total points
ID: 34894342
0
 
LVL 11

Assisted Solution

by:MajorBigDeal
MajorBigDeal earned 71 total points
ID: 34894355
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
 
LVL 2

Assisted Solution

by:HSIHSA
HSIHSA earned 71 total points
ID: 34894430
0
 

Author Closing Comment

by:mawingho
ID: 34894843
thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question