[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 930
  • Last Modified:

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).
0
SiraX
Asked:
SiraX
  • 2
  • 2
2 Solutions
 
anilmaneCommented:
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,

bye
0
 
waterhiddenCommented:
try:

Request.ServerVariables("REMOTE_USER")
0
 
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?
0
 
SiraXAuthor Commented:
it works now ... I had to remove the anonymous access on the virtual directory/website.

thnx
0
 
anilmaneCommented:
It was my pleasure to help you out.Thats why we are here...

0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now