How do I o get Winodws Authentication working with ASP.Net Core (net 6) Web API hosted on IIS 10

2022-03-03T13:38:26.133+00:00

Hi all,

We are struggling to host a ASP.Net core 6 web api in IIS using Windows authentication. This is what we have done so far. In our program.cs we have the following code snippets:

...

builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
.AddNegotiate();

builder.Services.AddAuthorization(options =>
{
// By default, all incoming requests will be authorized according to the default policy.
options.FallbackPolicy = options.DefaultPolicy;
});

...

if (app.Environment.IsDevelopment() )
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI();
}
else
{
app.UseHsts();
}

app.UseHttpsRedirection();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();

app.Run();

In IIS we've created an app pool using a dedicated active directory account configured as No managed code, the web site is configured to use Windows Auth with this app pool and uses https with a valid certificate, SSL enabled.

We also registered the website with this service account using SETSPN.

The app pool has access to the folder as well as the accounts that would be calling the Web API. Speaking of which here is one of the example end points used to test:

namespace mynamespace
{
[ApiController]
//[Authorize] Doesnt seem to make any difference if this is included or not
public class MyController : ControllerBase
{

     ....

          [HttpGet]
    [Route("api/v-1/[controller]/[action]")]
    //[Authorize] -- Not sure if this is required or not but doesnt seem to make a difference
    public ActionResult<string> TestConnected()
    {
        return "Connected";
    }

}

Whenever we call the endpoint either by code or Postman we are requested to enter credentials on entering credentials these are rejected. We get 401.1 or 401. 2 errors.

Does anyone have any ideas as to what the problem may be.

Thanks in advance

Darren

Developer technologies | ASP.NET | ASP.NET Core
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.