ASP.NET Core 3 起架設在 Windows IIS 方式改變

最近要升級 windows 伺服器的 ASP.NET Core 2.1 專案到 3.1 版本,發現 Windows 架設在 IIS 上面的方式有所改變。

一. 除了反向代理外,從 ASP.NET Core 3.0 起內建對 IIS in-process-hosting 預設支援(參考),可以不需要把 IIS Pool CLR 版本改為沒有 Managed 程式碼(請參考),只能依賴 kestrel server 運行 web 引擎。

現在可以去除 kestrel 代表說,它避免IIS 和 Kestrel 之間的額外網路傳遞,提供更好的性能,照官方說法佔用資源也會減少,相關效能測試可以參考(Rick Strahl文章)

這對跟我一樣,必須沿用 windows 主機無法替換 Linux 情況是一個好消息!

二. 注意 IIS In-process hosting 每個 app 需要建立一個專門的 pool
沒辦法像 asp.net mvc 一樣,可以多個應用使用同一個 pool 管理。

這點可以參考我在 S.O 發問Brando Zhang 的回答:

Sharing an app pool among apps isn’t supported. Use one app pool per app.

否則會出現錯誤 HTTP Error 500.35 - ANCM Multiple In-Process Applications in same Process

三. 雖然 ASP.NET Core 3.1 可以跟 Runtime 環境一起打包成單一執行檔(self-contained single file),但遺憾,只對 kestrel server 有效,沒有安裝 Runtime 的 IIS Server 還是需要安裝 Hosting Bundle

沒辦法像 .net core console 丟一個執行檔,別人就能開箱即用的效果。

圖片:在沒有安裝 asp.net core runtime 的 server ,運行 self-contained runtime 的 kestrel core app

圖片:同樣文件運行在 IIS 會報 500.19 錯誤