Alright Stackoverflow, after much fruitless research I've ended up here!
I am attempting to get a .NET Core 2.0 site hosted out of IIS with Windows Authentication and SSL, and no matter what I try I continue to get inconsistent/intermittent 403 Access Denied errors.
If there was something dead-wrong, I would expect it never to work. However, it works maybe ~3/10 times if I restart the site and the app pool. There is nothing useful that I can find in the Event Viewer, Application Logs, or IIS trace logs.
Things I have done in no particular order:
One more detail is that I am trying to authenticate with users from a different domain, where a one-way trust is set up. I am remoting into the host with credentials from the 'other' domain, so it has visibility.
Here is my web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MCP.MVP.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true" startupTimeLimit="3600" requestTimeout="23:00:00" />
<defaultDocument>
<files>
<add value="/home/index" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
<!--ProjectGuid: [REDACTED] -->
From Startup.cs:
services.AddAuthentication(IISDefaults.AuthenticationScheme);
services.Configure<IISOptions>(options =>
{
options.AutomaticAuthentication = true;
});
From Program.cs
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
Using Authorize attributes everywhere:
[Authorize(Policy = "RequireViewerRole")]
Authorization Glue, where Configuration["RequireViewerRoles"] is a comma delimited list of domain groups:
services.AddAuthorization(options =>
{
options.AddPolicy("RequireViewerRole", policy => policy.RequireRole(Configuration["RequireViewerRoles"].Split(',')));
});
Have I entered .NET Core 2.0 bug territory, or am I missing something?
It turned out to be a massive red herring!
It was a 401.2 "invalid server configuration" error. I finally noticed a pattern where the application would work if I opened up the folder security permissions dialogue, which would forcibly hit the domain-controller and cache the group names from the user domain. The application would work fine for about 5 minutes, before refusing to authenticate again with no other changes made.
The issue was solved by configuring the domain name on the group, which is obvious in retrospect. (DomainName\\Domain Users). The fact that it worked at all without the domain name led to a lot of confusion. There was nothing to indicate this error from the IIS logs, and ultimately it was solved by trial and error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With