Reputation: 793
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.
Upvotes: 1
Views: 1766
Reputation: 793
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
Upvotes: 3