How to find current Windows User \

I have a web application in ASP.NET
I am using Forms Authentication with AD.
On the login screen I want to fill in the current windows user's name in the login form.
How do I do this ?
LVL 1
vu3lmgAsked:
Who is Participating?
 
vu3lmgConnect With a Mentor Author Commented:
I changed the properties of Login.aspx as shown in the image below and
HttpContext.Current.Request.ServerVariables["LOGON_USER"].ToString();

Open in new window

returns the current windows.
LoginPropertiesForIIS.bmp
0
 
Seaton007Commented:
Here is an example of how to get the current user name (it puts the user name in the "strUserName" variable):
Dim strUserName

Set objNetwork = CreateObject("WScript.Network")
strUserName = objNetwork.UserName

Open in new window

0
 
vu3lmgAuthor Commented:
Dear Seaton007
I am using C#, which "using ..." includes this "WScript.NetWork" class ?
-VU3LMG
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Obadiah ChristopherCommented:
Use

HttpContext.Current.User.Identity

Open in new window



http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx
0
 
vu3lmgAuthor Commented:
Dear informaniac
HttpContext.Current.User.Identity 

Open in new window

is returning blank, what could be the reason ?
VU3LMG
0
 
vu3lmgAuthor Commented:
Just FYI I am using "Forms Authentication with AD user"
not "Windows Authentication"
When I use "Environment.UserName" it returns "NETWORK SERVICE".

VU3LMG
0
 
vu3lmgAuthor Commented:
Contaced an expert and got the advise as mentioned in the solution above.
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.