如何在IIS10中正确启动asp.net应用程序

时间:2022-09-10 03:35:00

I'm trying to get my ASP.NET application to automatically start whenever the application pool is running.

我正在尝试让我的ASP.NET应用程序在应用程序池运行时自动启动。

As per the lots and lots of references online I have already done the following:

根据网上很多很多参考资料,我已经做了以下工作:

  • Set the Application Pool to StartMode=AlwaysRunning
  • 将应用程序池设置为StartMode = AlwaysRunning

  • Set the site in question (that belongs to beforementioned Pool) to preloadEnabled=true
  • 将有问题的站点(属于前面提到的池)设置为preloadEnabled = true

  • Install the Application Initialization feature to the Windows installation
  • 将应用程序初始化功能安装到Windows安装

  • Add the <applicationInitialization> node to the web.config's <system.webServer> node
  • 节点添加到web.config的 节点

The web application is based on Owin and has a simple log4net logging statement in it's Startup.Configuration() method. Now when restarting IIS I see that the w3svc.exe process is running, so I know the StartMode=AlwaysRunning is working. There are however no logging messages in the log file.

Web应用程序基于Owin,并在其Startup.Configuration()方法中有一个简单的log4net日志记录语句。现在重新启动IIS时,我看到w3svc.exe进程正在运行,所以我知道StartMode = AlwaysRunning正在运行。但是,日志文件中没有日志消息。

Navigating to any url (even a nonexisting one) in the application will start the app and add the log line.

导航到应用程序中的任何URL(甚至是不存在的URL)将启动应用程序并添加日志行。

Because of the actual work that's done in the startup of the application I really want the application to truly preload, but I seem to be unable to get it done.

由于在应用程序启动时完成的实际工作,我真的希望应用程序真正预加载,但我似乎无法完成它。

Searching this site I have unfortunately not been able to find a solution.

搜索这个网站遗憾的是我无法找到解决方案。

Thanks in advance.

提前致谢。

1 个解决方案

#1


12  

To answer my own question for future generations, it seems I was on the right track. To get the application to start in IIS10 (and I assume in IIS 8 as well) you only need the following three steps:

为了回答我自己的后代问题,似乎我走在正确的轨道上。要让应用程序在IIS10中启动(我还假设在IIS 8中),您只需要以下三个步骤:

  1. Set the Application Pool to StartMode=AlwaysRunning to make sure the w3svc.exe process is always running for the App Pool.
  2. 将应用程序池设置为StartMode = AlwaysRunning,以确保始终为应用程序池运行w3svc.exe进程。

  3. Set the site in question (that belongs to beforementioned Pool) to preloadEnabled=true
  4. 将有问题的站点(属于前面提到的池)设置为preloadEnabled = true

  5. Install the Application Initialization feature to the Windows installation as per the instructions here.
  6. 按照此处的说明将应用程序初始化功能安装到Windows安装。

One important thing to note is that if the Application Initialization task was not previously installed on the machine you must reboot the machine. This is what I missed the last time which led to quite some time wasted looking for other things :(

需要注意的一件重要事情是,如果以前未在计算机上安装应用程序初始化任务,则必须重新启动计算机。这是我错过了最后一次导致相当一段时间浪费寻找其他东西:(

Anyway, setting up those three things will cause the app to actually go through it's initialization, which is especially useful if you want to setup some scheduling task (ea using the Quartz NuGet package).

无论如何,设置这三件事将导致应用程序实际完成初始化,这对于您想要设置一些调度任务(使用Quartz NuGet包)非常有用。

Note by the way that if you setup auto initialization like above, the application will also automatically start after the shutdown timeout has expired and on application pool recycles.

请注意,如果您设置如上所述的自动初始化,应用程序也将在关闭超时到期后以及应用程序池回收时自动启动。

#1


12  

To answer my own question for future generations, it seems I was on the right track. To get the application to start in IIS10 (and I assume in IIS 8 as well) you only need the following three steps:

为了回答我自己的后代问题,似乎我走在正确的轨道上。要让应用程序在IIS10中启动(我还假设在IIS 8中),您只需要以下三个步骤:

  1. Set the Application Pool to StartMode=AlwaysRunning to make sure the w3svc.exe process is always running for the App Pool.
  2. 将应用程序池设置为StartMode = AlwaysRunning,以确保始终为应用程序池运行w3svc.exe进程。

  3. Set the site in question (that belongs to beforementioned Pool) to preloadEnabled=true
  4. 将有问题的站点(属于前面提到的池)设置为preloadEnabled = true

  5. Install the Application Initialization feature to the Windows installation as per the instructions here.
  6. 按照此处的说明将应用程序初始化功能安装到Windows安装。

One important thing to note is that if the Application Initialization task was not previously installed on the machine you must reboot the machine. This is what I missed the last time which led to quite some time wasted looking for other things :(

需要注意的一件重要事情是,如果以前未在计算机上安装应用程序初始化任务,则必须重新启动计算机。这是我错过了最后一次导致相当一段时间浪费寻找其他东西:(

Anyway, setting up those three things will cause the app to actually go through it's initialization, which is especially useful if you want to setup some scheduling task (ea using the Quartz NuGet package).

无论如何,设置这三件事将导致应用程序实际完成初始化,这对于您想要设置一些调度任务(使用Quartz NuGet包)非常有用。

Note by the way that if you setup auto initialization like above, the application will also automatically start after the shutdown timeout has expired and on application pool recycles.

请注意,如果您设置如上所述的自动初始化,应用程序也将在关闭超时到期后以及应用程序池回收时自动启动。