0
votes

I am trying to add windows Authentication to new asp.net core 2.2 version website. While creating website `1) I have changed the authentication mode to "Windows authentication". Verified in launchsettings.json

"windowsAuthentication" = true, "AnonymousAuthentication": false,

2) Added the below line to Startup.cs file under ConfigServices.

services.AddAuthentication(IISDefaults.AuthenticationScheme);

3) I am currently running in my local so In my local computer, Enabled -> Turn Windows features on or off->Internet Information Services->Security-> "Windows Authentication"

Problem On local system: 1) windows pop up is not displayed to enter username and password 2) I need to display Windows User Name and Directory details(Department eg: IT, Sales department based on username) how to achieve it. Any suggestion would be helpful.

1
You asked two completely different things. How to enable or rather, how to check if Windows authentication is working and how to look up AD information on a user, which has nothing to do with Windows AuthenticationPanagiotis Kanavos

1 Answers

1
votes

1) windows pop up is not displayed to enter username and password

If you use IIS to host the web application, you should enable the windows auth by using IIS management console or modify the web.config file.

As far as I know the launchsettings.json has below feature:

  • Is only used on the local development machine.
  • Is not deployed.
  • contains profile settings.

That means the windows authentication setting will not be enabled in IIS after deployed. You should enable it by using IIS management console.

Open the authentication:

enter image description here

Disable the anonymous authentication and enable the windows authentication

enter image description here

Or you could add below settings in your web.config

<system.webServer>
    <security>
        <authentication>
            <anonymousAuthentication enabled="false" />
            <windowsAuthentication enabled="true" />
        </authentication>
    </security>
</system.webServer>

If you want to use kestrel instead of IIS to host the application, you should use HTTP.SYS in your application. More details about how to use it ,you could refer to this article.

2) I need to display Windows User Name and Directory details(Department eg: IT, Sales department based on username)

If you want to get the user name, I suggest you could try to use User.Identity.Name.

If you want to get current user's department, I suggest you could try to use this solution.