Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-14
10
Medium Priority
?
1,514 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 288 total points
ID: 34893940
Have you tried: Context.User.Identity.Name


0
 
LVL 8

Assisted Solution

by:PagodNaUtak
PagodNaUtak earned 288 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 288 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Assisted Solution

by:s_chilkury
s_chilkury earned 284 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 284 total points
ID: 34894342
0
 
LVL 11

Assisted Solution

by:MajorBigDeal
MajorBigDeal earned 284 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 284 total points
ID: 34894430
0
 

Author Closing Comment

by:mawingho
ID: 34894843
thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

916 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