We help IT Professionals succeed at work.

How to find current Windows User \

vu3lmg
vu3lmg asked
on
Medium Priority
562 Views
Last Modified: 2012-08-27
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 ?
Comment
Watch Question

CERTIFIED EXPERT

Commented:
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

Author

Commented:
Dear Seaton007
I am using C#, which "using ..." includes this "WScript.NetWork" class ?
-VU3LMG
Obadiah ChristopherDeveloper User Interface
CERTIFIED EXPERT

Commented:

Author

Commented:
Dear informaniac
HttpContext.Current.User.Identity 

Open in new window

is returning blank, what could be the reason ?
VU3LMG

Author

Commented:
Just FYI I am using "Forms Authentication with AD user"
not "Windows Authentication"
When I use "Environment.UserName" it returns "NETWORK SERVICE".

VU3LMG
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

Author

Commented:
Contaced an expert and got the advise as mentioned in the solution above.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.