How to disable windows authentication only for Web API inside a .net core MVC web application

asp.net-core asp.net-core-mvc entity-framework-core

Question

I have a .NET Core MVC web application and I have set windows authentication for that project. Now I have added an API controller in the same project and for which I don't want authentication. Is it possible to disable windows authentication only for API ? The reason why I have created the application with windows authentication is to just log the current user details who is accessing my application via browser.

1
0
12/20/2019 1:39:26 PM

Accepted Answer

After spending several hours I have found the following solution: In launchsettings.json set following values

"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": true,

Add the following line inside startup.cs ConfigureServices

services.AddAuthentication(IISDefaults.AuthenticationScheme);

add

[Authorize] 

attribute in controller where we need to get the user name using namespace

(Microsoft.AspNetCore.Authorization)

Thus, I am able to hit the API without giving authorization and I am able to get the current user details in the MVC controller.

This one helped me in figuring out the solution : https://github.com/aspnet/AspNetCore/issues/2913

2
12/24/2019 6:32:24 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow