0

I have website in mvc c#, running on a server. I want to bypass the login page and authenticate a user if the user is present in active directory. For my website, i have forms authentication and anonymous authentication enabled.

The problem is, i want to find out the name of user who is visiting the website. The user can be present on internet. With this name, i will do a lookup in Active directory and do the validation.

I am unable to find the user name. Any help would be appreciated.

Thanks.

  • Did you check http://stackoverflow.com/questions/18452878/get-domain-user-id-in-asp-net? – Vojtěch Dohnal Dec 19 '14 at 20:26
  • @VojtěchDohnal This always shows the name of the app pool running the site. Whereas I am looking to find out the user name or computer name of the person hitting the website. Be it on internet or intranet. – pankaj sharma Jan 06 '15 at 15:25

1 Answers1

0

You can have Active Directory Authentication in mvc by using Active Directory as the Membership Provider and get the username as

MembershipUser user = Membership.GetUser();
if (user != null)
    string name = user.UserName;
Tushar Gupta
  • 15,504
  • 1
  • 29
  • 47