'How to Publish DotNet Core (v5.0) Web Api to IIS?
First thing I did was install the .NET Core Hosting Bundle on the IIS server; I have also stopped and re-started IIS;
I've tested and can confirm my app runs on Krestel, but I am struggling to get it running (in-proc) in IIS;
Running with Krestel (good/pass):
On my local PC, "Publish" as Framework-dependent to MyAppFolder (this folder now contains all the compiled assets for my app, including exec and dll's)
Move MyAppFolder somewhere on the IIS server;
Run the executable (MyWebApi.exe) directly on the cmd line , I get the default Now listening on: http://localhost:5000
If I navigate to an end point with a Browser, http://localhost:5000/MyResource/123 , this GET request produces the desired json result;
Running with IIS (bad/fail):
- As stated above, NET Core Hosting Bundle is installed, including stop/start the iis server
- Created an App Pool (No Managed Code)
- Created a Virtual App on the IIS Manager (MyVirtualApp), which points to the folder containing all the assets for my app (same folder that works with Krestel)
That should be it, I think, but it doesn't work ? Did I miss any steps ? When I point a Browser to my resource http://localhost/MyVirtualApp/MyResource/123 , I get a 404!
Additional Info:
//Program.cs
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
Docs say I don't need to explicitly UseIIS, as CreateDefaultBuilder will use IIS or Krestel;
Also, dotnet --info gives the below:
Host (useful for support):
Version: 5.0.17
Commit: 6a98414363
.NET SDKs installed:
No SDKs were found.
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
The 404 Error page: (as given by IIS)
Detailed Error Information:
Module: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error Code: 0x80070002
This IIS error appears to be related to routing, Routing HTTP Error 404.0 0x80070002
Solution 1:[1]
It turns out the "target folder" produced by the "Publish" wizard in Visual Studio produces a parent folder containing my app's exe and dll's, plus children subfolders called publish, ref, runtimes;
In IIS I configured my site's physical path to be at the parent folder level, when it should have been to the publish folder ! (I see no reason for the team at MS to generate files at the parent folder, and again inside the publish folder - why double up and make it confusing !).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | joedotnot |
