Featured image of post 在 IIS 設定 ASP.NET 應用程式保持永遠運行

在 IIS 設定 ASP.NET 應用程式保持永遠運行

本文設定 IIS 避免 ASP.NET 應用程式在 IIS 中 20 分鐘內無人訪問後自動 Shutdown

環境

  • Windows Server 2022
  • IIS 10

設定

1. IIS Application Pools

  1. Application Pools, 選擇站台應用程式,右鍵 Advance Settings
  2. General > Start Mode > AlwaysRunning default OnDemand
  3. Process Model > Idle Time-out > 0 default 20
  4. Recycling > Regular Time Interval > 0 default 1740

2. IIS Site

  1. Sites > Admin ( Your Site ) > 最右邊 Manager WebSIte > Advanced Settings…
  2. General > Preload Enable > true

3. 安裝 Application Initialization 服務

目的在於站台重啟後,自動啟動ASP.NET應用程式

Windows 2022 有兩種方式新增 Feature

  • 第一種

    1. Star > Control Panel > Programs and Features
    2. 選擇左邊 Turn Windows features on or off
  • 第二種

    1. Star > Server Manager
    2. 右上角 Manage > Add Roles and Features

安裝 Feature 步驟

  • Step 1. Role-base or feature-base installation
  • Step 2. Select a server from the server pool
  • Step 3. Roles > Web Server (IIS) > Web Server > Application Development > Application Initialization

Add Feature Structure

設定Web.Config

在應用程式重啟後會自動觸發 “/” 的請求

1
2
3
4
5
6
7
<configuration>
  <system.webServer>
    <applicationInitialization doAppInitAfterRestart="true">
      <add initializationPage="/" />
    </applicationInitialization>
  </system.webServer>
</configuration>

參考

dinostack.cc
使用 Hugo 建立
主題 StackJimmy 設計