Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
613 views
in Technique[技术] by (71.8m points)

iis - How to properly autostart an asp.net application in IIS10

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

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

  • Set the Application Pool to StartMode=AlwaysRunning
  • Set the site in question (that belongs to beforementioned Pool) to preloadEnabled=true
  • Install the Application Initialization feature to the Windows installation
  • Add the <applicationInitialization> node to the web.config's <system.webServer> node

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.

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. Set the Application Pool to StartMode=AlwaysRunning to make sure the w3svc.exe process is always running for the App Pool.
  2. Set the site in question (that belongs to beforementioned Pool) to preloadEnabled=true
  3. Install the Application Initialization feature to the Windows installation as per the instructions here.

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).

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...