IIS - Capture user logged in to the machine without using Windows authentication

Asked

Viewed 1,240 times

0

I have a website that uses the user logged into the computer to validate what functionality he will have access to within the site. To capture the user logged into the machine I am using the code below, I needed to change the authentication of IIS for Windows Authentication, but it keeps requesting user and password when accessing the site for the first time.

string userNameWindows = this.Context.Request.LogonUserIdentity.Name;

How do I capture the logged-in user on the machine without requesting login/password on first access.

inserir a descrição da imagem aqui

1 answer

0


If you want to check the Windows user with Forms Authentication, you can use this code:

System.Security.Principal.WindowsIdentity.GetCurrent().Name.Tostring()

However, it is not safe. Easily the value of this method will be NT AUTHORITY SYSTEM or the user configured to run the application on IIS. This is because the authentication is with the impersonate property enabled.

Also try this code:

System.Security.Principal.WindowsPrincipal user;
user = new WindowsPrincipal(this.Request.LogonUserIdentity);
this.Request.LogonUserIdentity.Impersonate();
user_name = user_name.Substring(user_name.LastIndexOf("\\") + 1);

In case none of the cases help you, take a look at this link in English: https://stackoverflow.com/questions/16184685/how-do-i-get-the-currently-loggedin-windows-account-from-an-asp-net-page

  • Felipe, I tried to use the methods you suggested but I was unsuccessful. If I use the Forms Authentication message : 401 - Unauthorized: Access is denied due to invalid credentials. You do not have permission to view this directory or page using the credentials that you supplied. When using the other method it still asks Login/Password on the first access, and should capture the user logged in the machine.

  • Victor, I did a search and found some points to analyze: * Check to see if anonymous IIS access authentication is disabled. * Web server must be in the same network domain of the client machine, if not, there must be a trust between the servers for this authentication delegation. * Check if browser settings allow auto-logon: Tools > Internet options > Security(Tab) > Custom Level(button) > Login > Auto-logon with current username and password.

  • Felipe thank you so much, I finally got it. . The IIS settings were correct, what was impacting the problem were the browser settings that requested login and password when entering the Site.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.