Get username of page visitor with c# (aspx)

Is there a possibility to get the username of a page visitor using C# (ASPX)?

We have an Active Directory server and we want to identify the users immediatly on our intranet page (so that they don't have to indicate the username when the have to make a login on restricted areas).
Who is Participating?
anilmaneConnect With a Mentor Commented:
Try one of the following,

1> string user = User.Identity.Name
2> string user = System.Environment.UserName
3> string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name

Web.config Settings should be
<identity impersonate="true"/>
<authentication mode="Windows" />

.Hope this helps,

waterhiddenConnect With a Mentor Commented:

SiraXAuthor Commented:
sorry but nothing of all that works ...

anilmane for 1> it returns nothing, 2 and 3 is almost the same but returns the user which is running the script on the IIS (IUSR_<Machinename>) and 3> returns nothing as well. (I also added the identity tag to web.config ... auth. mode was already set to "Windows".)

waterhidden, the server variable returns nothing as well :(

I know that in PHP the server variable REMOTE_USER worked but here it seems that it doesn't work. Could it be a configuration problem in IIS oder web.config?
SiraXAuthor Commented:
it works now ... I had to remove the anonymous access on the virtual directory/website.

It was my pleasure to help you out.Thats why we are here...

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.