Reputation: 423
I have a .Net Core 1.0 web application targeting framework 4.6 that uses Windows Authentication (intranet site). It runs fine in development environment under IIS Express.
In startup.cs I have:
services.Configure<IISOptions>(options => {
options.ForwardWindowsAuthentication = true;
});
Once deployed to IIS 8 in Windows Server 2012, however, the application errors out on the line:
var userName = context.User.Identity.Name;
With "Object reference not set to an instance of an object" error. In web.config, I have:
<system.web>
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
</system.web>
In IIS Manager under "Authentication" for the site, everything is disabled except for "Windows Authentication" as well. Another ASP.NET MVC 4 site on that same server with same settings in IIS works fine. Anything else I can try to get this working??
Upvotes: 1
Views: 1251
Reputation: 423
The Config settings below resolved this issue, specifically the forwardWindowsAuthToken=true:
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="<path to app>" arguments="" stdoutLogEnabled="true" stdoutLogFile="<outpath>" forwardWindowsAuthToken="true" />
<security>
<authentication>
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
Upvotes: 2