locked
AD account of the user logged on the machine (c# and asp.net) RRS feed

  • Question

  • User-1048787396 posted

    Hi. What is the best way to get AD account (domain name and user name) of the user who is currently logged on the machine? I’m using ASP.net and C#. Thanks in advance.

    Monday, February 27, 2017 5:23 AM

All replies

  • User197322208 posted

    Activate Windows Authentication and disable anonymous in IIS 

    Monday, February 27, 2017 7:40 AM
  • User-1048787396 posted

    Thanks Andrei. I forgot to say that this is in fact "intranet" application and I'm using web forms authentication.

    Monday, February 27, 2017 11:12 PM
  • User1771544211 posted

    Hi mgataric,

    You can use the following code to get the current logged in user name.

    var name = System.Web.HttpContext.Current.User.Identity.Name;

    Best Regards,

    Jean

    Tuesday, February 28, 2017 6:21 AM
  • User197322208 posted

    I forgot to say that this is in fact "intranet" application and I'm using web forms authentication.

    I do not understand why it uses web forms authentication instead of AD authentication. 

    Does the user enters HIS windows credentials on the web forms ?

    Tuesday, February 28, 2017 12:26 PM
  • User-1048787396 posted

    Thank you Jean and Andrei. I'll try Jean's suggestion. The reason for "web forms" authentication is that not all users in the domain are permitted access to the site. I inherited this web site and I'm beginner in the field. Do you have a better way to authenticate users, Andrei? This works, but if there is a better way, I might use it. Once again: I want only certain users in the domain to have access to the site. Right now there is a password presented to the user at the moment when she/he wants to access it.

    Thanks again Andrei.

    Wednesday, March 1, 2017 12:42 AM