.NET Core Running on IIS
I'm configuring an application that we've migrated to .NET Core. It's hosted on Windows Virtual Machines running IIS. It seems like an easy task, right? It has many challenges.
- The published folder of my application has a
wwwroot
directory which my IIS application would point to in the past. Not anymore. Theweb.config
in the root folder points to the application's executable. One thing to note is that it also requires a new module AspNetCoreModule and if you don't have it installed you'll get a 404 response.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\webapp1.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
- Let's then install this new module which is part of the Windows Server Hosting (x64 & x86) bundle which you can download from here or this direct link.
The issue I had was that my virtual machines, because of security, don't have access to the internet. So every time I tried to install the Windows Server Hosting it would fail. Later on, I found on this GitHub issue that was because it required VC++ 2015 installed which you can download here. After installing VC++ 2015, the installation of the Windows Server Hosting succeeds.
- Something else you have to do is to configure your application to use the IIS integration.
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
//here it is
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
- Another issue I had was because a workaround we had in place for our application to run under a subdirectory in IIS. We had this mapping in place which is no longer required.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
{
app.Map("/subdirectory1", (app1) => Configure_Proper(app1, env, loggerfactory));
}
public void Configure_Proper(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
{
//the actual configuration
}
So I've updated to this:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
{
//the actual configuration
}
- And at last, not really relevant to IIS itself and might not be relevant to you. Previously when we ran
dnu publish
it would automatically runnpm install
,bower install
and somegulp
tasks. Withdotnet publish
I didn't have that. So I had to add some extra steps to my build pipeline to run these commands.
Hope it helps. Cheers.