Jeremy Davis
Jeremy Davis
Sitecore, C# and web development
Article printed from:

Hosting ASP.Net Core 7 Preview 7 under IIS

Fresh server gives fresh pain

Published 12 September 2022

I was hacking up an app as a personal project recently, and decided to try out the latest preview (Number 7) of ASP.Net Core for .Net 7. I happened to be deploying this project to a server which had never run ASP.Net Core before, and that deployment left me scratching my head for some time. So in case this issue hits others, here's what happened to me:

Following the docs

I'd built myself an app, and it was running fine under VS 2022 on my laptop. So I went to the .Net docs website to see what was required to put this onto my server. Microsoft are pretty pro-active here, so there are already doc pages for hosting ASP.Net Core 7 under IIS.

Reading through that, the instructions seemed to be:

  • Be running Windows Server 2012 R2 or later
  • Install the .Net 7 and ASP.Net Core 7 runtimes for the relevent preview version
  • Install the "ASP.Net Core Module / Hosting Bundle"
  • Create an IIS site configured for "No Managed Code"
  • Deploy the ASP.Net Core site into the folder for the IIS site

Seems simple? In the past there had been some extra complexity about the difference between "in process" and "out of process" hosting for ASP.Net Core websites with IIS. But in the current versions that seems to default to "in process" with sensible configuration. So it seemed to me that I did not need to do anything extra here.

First attempt

My server is running Windows Home Server 2016 - which seems like it meets the core O/S requirement above. So that should be fine. I had deployed a couple of earlier previews of .Net 7 onto this box, but not the ASP.Net Core bits. So I went to the downloads page for Preview 7 and looked for the relevant bits:

Downloads page for .Net 7 Preview 7

Based on the info there, I grabbed the hosting bundle from there and ran the installer - which ran without errors. I rebooted the server afterwards, for safety.

Creating the IIS site was easy, and I disabled the .Net 4 runtime, to leave it in the "no managed code" state as instructed:

App pool config dialog in IIS, showing no managed code

With that done, I published from Visual Studio into my freshly created website folder on the server, and fired up a browser:

A browser window showing the basic IIS 500-error screen with no details

Not good...

So I went and looked for logs. This looks like the IIS error page, rather than an ASP.Net one - so I went to the event log first. Nothing there - I could see no new events being created when I refreshed the page. Looking at the IIS logs for this site I could see entries for the request, and they were marked as being returned with 500 errors - but you don't get details there. Just to check I tried enabling the ASP.Net Core stdout logging for the app, but nothing got created there. (Unsurprising - a vanilla IIS error suggests .Net never got called here)

At this point I was a bit stumped, so I spent some time in Google...

Finding a cause

Googling for stuff about "my ASP.Net Core app gives a 500 error on IIS" brought back a collection of the usual Stack Overflow and blog post responses. These seemed to fall into a few categories:

  • Your app is running, but you've messed up config for something like a database, so it crashes on startup
  • Turn on the logging to find out what's up!
  • Did you remember to install the hosting bundle?

None of those seemed appropriate. My app was entirely self-contained - so runtime config wasn't an issue. I'd tried logging and got nothing. And I definitely installed the hosting bundle. But I came across one blog post which was talking about how the hosting bundle can be messed up by missing system-level config. So I tried looking into this.

Interestingly, the %WinDir%\System32\Inetsrv\Config\applicationHost.config config file mentioned there did not include any reference to aspNetCore - but this made me realise that IIS was supposed to have a module installed for ASP.Net Core hosting. When I went back and looked at the IIS config for my site, I could not see this:

IIS Modules for the site in question, not showing the ASP.Net Core module

(It was also missing from the overall server config - so it wasn't just an issue for my particular site)

Now that sounded like a sensible root cause - if the module was missing, then my site would never run - and IIS could well suffer a "what on earth do I do to handle this code?" error as a result. (Though I'm still not sure why I can't see that in the event logs)

I went back to Google and discovered that this module should live under %ProgramFiles%\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll and I checked for that. The folder did not exist at all. So further proof that the module was missing.

A fix

Google didn't give me any help about the specifics I'd discovered. But I did stumble onto a fix myself: I wondered if this might be a ".Net 7 is too bleeding-edge to work on my server" issue, and tried downloading the hosting bundle supplied for Asp.Net Core 6 instead. That's available on the .Net 6 version of the hosting page cited above:

The download link for the .Net 6 version of the ASP.Net Core hosting bundle

I ran that, and bingo! My site started to work despite the version difference. And I could now see the module on my site too:

The IIS modules screen, now showing the ASP.Net Core hosting module

So there you have it. For reasons I can't work out (there were no log errors about it - even in the detailed installer log) the .Net 7 Hosting Bundle installer didn't work correctly on my server, but the .Net 6 one did. I do wonder if this might be related to having had older previews of .Net 7 installed in the past?

↑ Back to top