Solved

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

Posted on 2011-02-14
10
1,398 Views
Last Modified: 2012-05-11
How to get the windows login name or domain username?
0
Comment
Question by:mawingho
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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