How do I get a .Net Core website hosted in IIS to start immediately?

后端 未结 3 1746
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 10:41

This blog post explains how when a .Net Core website is hosted in IIS, the website code does not actually get run until the first request comes in to IIS:

https://we

相关标签:
3条回答
  • 2021-01-18 11:03

    I tried every auto start option I read about, and finally came up with the one combination that solved my problem. On the application pool set "Start Mode" to "AlwaysRunning" and on the website, itself, set "Preload Enabled" to "true". With those two settings, the application starts immediately. Now, I did discover something unexpected. When the website is in a stopped state, my application continues to run. What I found is that if I ever want to stop my application, I have to stop the application pool, not the website.

    If this isn't working, also make sure that the Application Initialization feature is installed for IIS, since it is optional.

    https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-application-initialization

    Core 3.1 Update: I have confirmed that this solution does work with Core 3.1. If you find that it is not working, double check that you have the Application Initialization feature installed for IIS. The downside to this solution is that stopping the app pool immediately stops my application, without a way to gracefully end. If the Application Initialization feature is not installed, my application will gracefully stop when the app pool is stopped, but then the application does not start automatically.

    0 讨论(0)
  • 2021-01-18 11:06

    If you are using IIS there is a checkbox which starts the website immediately, you can try that on IIS settings.

    UPDATE: see point 6 from below article:

    https://docs.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x

    0 讨论(0)
  • 2021-01-18 11:16

    I tried the solution above by @eric, and it didn't work by itself. Adding this to my .CSPROJ file (in addition to his suggestions) finally did the trick:

    <PropertyGroup>
        <ServerGarbageCollection>true</ServerGarbageCollection>
        <ConcurrentGarbageCollection>false</ConcurrentGarbageCollection>
    </PropertyGroup>
    
    0 讨论(0)
提交回复
热议问题