简体   繁体   English

IIS 8.5 - 应用程序初始化无效

[英]IIS 8.5 - Application initialization not working

I have installed Application Initialization, set the website's application pool Start Mode to "Always Running", and set Preload Enabled = "True" in the advanced settings of the website. 我已经安装了应用程序初始化,将网站的应用程序池启动模式设置为“始终运行”,并在网站的高级设置中设置Preload Enabled =“True”。

However, if I recycle the application pool manually and wait 10 seconds, when I then reload the website, I still have to wait another 10 seconds for the website to warm up. 但是,如果我手动回收应用程序池并等待10秒钟,那么当我重新加载网站时,我仍然需要等待10秒才能让网站热身。 This indicates that the website is not starting. 这表明该网站尚未启动。

Looking at task manager, I can see that the application pool is running the whole time - even after a recycle. 查看任务管理器,我可以看到应用程序池一直在运行 - 即使在回收之后也是如此。 However, the memory usage is very low until I make my own request to the website. 但是,在我向网站提出自己的请求之前,内存使用率非常低。

One thing I have noticed is that I do not have a "Start Automatically" setting in the advanced settings of my website as per this link: https://blogs.msdn.microsoft.com/vijaysk/2012/10/11/iis-8-whats-new-website-settings/ 我注意到的一件事是,根据以下链接,我的网站的高级设置中没有“自动启动”设置: https//blogs.msdn.microsoft.com/vijaysk/2012/10/11/iis -8-什么,新网站的设置/

How can I get my application to auto-start? 如何让我的应用程序自动启动?

It turned out to be a whole load of settings which all had to be correct. 事实证明,这是一整套必须正确的设置。 You go through all of the steps to install the relevant components and make the various config changes as per this link: http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-application-initialization 您将完成所有步骤以安装相关组件,并根据以下链接进行各种配置更改: http//www.iis.net/learn/get-started/whats-new-in-iis-8/iis -80的应用程序初始化

The key part which was missing for me was an instruction in the Web.config as below. 对我来说缺少的关键部分是Web.config中的指令,如下所示。 I had it going to just "/Login" which is a valid route, but as soon as I switched it to "/[Controller]/[Action]" it worked. 我得到它只是“/登录”这是一个有效的路线,但一旦我切换到“/ [控制器] / [行动]”它工作。

The advantage of this route is that you can create a custom action which will also hit the database (initialising Entity Framework), and perform any other slow initialisation you wish. 此路由的优点是您可以创建自定义操作,该操作也将访问数据库(初始化实体框架),并执行您希望的任何其他慢速初始化。 For me, I just read a record out of a DB table, so I get ASP.NET auto-starting, and also save the few seconds it takes to warm up EF too :) 对我来说,我只是从数据库表中读取一条记录,所以我自动启动了ASP.NET,并且还节省了预热EF所需的几秒钟:)

<system.webServer>
  <applicationInitialization doAppInitAfterRestart="true" skipManagedModules="false">
      <add initializationPage="/Login/WarmUp" />
    </applicationInitialization>
</system.webServer>

Try Application Initialization setup: 尝试应用程序初始化设置:

I had similar issues and tried very hard with IIS 8.5 Windows Server 2012 R2. 我有类似的问题,并尝试使用IIS 8.5 Windows Server 2012 R2。 Everything in the IIS was set correctly after referring to so many sites however had missed the Application Initialization setup. 在引用了许多站点之后,IIS中的所有内容都已正确设置,但却错过了应用程序初始化设置。 Refer to the below link, Setup section. 请参阅以下链接,“设置”部分。

在此输入图像描述

https://www.iis.net/configreference/system.webserver/applicationinitialization https://www.iis.net/configreference/system.webserver/applicationinitialization

These articles are very good: 这些文章非常好:

Use IIS Application Initialization for keeping ASP.NET Apps alive 使用IIS应用程序初始化来保持ASP.NET应用程序的活动

IIS 8.0 Application Initialization IIS 8.0应用程序初始化

However in my case there was a problem with installing the Application Initialization Role . 但是在我的情况下,安装应用程序初始化角色时出现问题。

Check your IIS App's Modules listing. 检查IIS应用程序的模块列表。 Ensure ApplicationInitializationModule is present. 确保ApplicationInitializationModule存在。

在此输入图像描述

I needed to uninstall/re-install this module. 我需要卸载/重新安装此模块。

I have no idea what happened as this appeared to work at first, then weeks later during development it stopped. 我不知道发生了什么,因为它似乎首先工作,然后几周后在开发过程中它停止了。 No amount of tinkering/rework fixed it and I started to suspect I never actually saw this working. 没有任何修补/返工修复它,我开始怀疑我从来没有真正看到这个工作。

Issue resolved upon uninstall/re-install Applicaion Initialization Module role. 卸载/重新安装应用程序初始化模块角色时解决问题。

If anyone's wondering what to do in MVC when you have multiple areas to initialise, you need to put the area at the start, all within the root web.config file. 如果有人想知道在有多个区域初始化时要在MVC中做什么,则需要将该区域放在开头,所有这些都在根web.config文件中。 I was stuck for a while trying to put it in the area's web.config. 我被困了一段时间试图把它放在该区域的web.config中。 Also it's perfectly compatible with hybrid applications. 它还与混合应用程序完美兼容。

<add initializationPage="/NotMVC.aspx" />
<add initializationPage="/Area1/Controller/Action" />
<add initializationPage="/Area2/Controller/Action" />

There are multiple .config locations where these settings can be set. 有多个.config位置可以设置这些设置。

  1. Machine applicationHost.config (c:\\windows\\system32\\inetsrv\\Config) 机器applicationHost.config(c:\\ windows \\ system32 \\ inetsrv \\ Config)
  2. Website web.config (c:\\inetpub\\wwwroot for Default Web Site) 网站web.config(默认网站的c:\\ inetpub \\ wwwroot)
  3. Application web.config 应用程序web.config

I tried all but was only successful in configuring 3, the application web.config. 我尝试了所有但只是成功配置3,应用程序web.config。 My specific use case was calling a GET method on a WCF service. 我的具体用例是在WCF服务上调用GET方法。

The steps for application initialization are found in the other answers too. 应用程序初始化的步骤也可以在其他答案中找到。 Here is one that was most helpful. 这是最有帮助的一个。 IIS 8.0 Application Initialization IIS 8.0应用程序初始化

  1. Install the Windows feature Application Initialization ( Web-AppInit ) 安装Windows功能应用程序初始化( Web-AppInit
  2. Set the IIS app pool Start mode = AlwaysRunning 设置IIS应用程序池Start mode = AlwaysRunning
  3. Set the IIS application Preload Enabled = true 设置IIS应用程序Preload Enabled = true
  4. Add to the application web.config 添加到应用程序web.config

     <system.webServer> <applicationInitialization doAppInitAfterRestart="true" skipManagedModules="true"> <add initializationPage="/Service.svc/Method/Parameter" /> </applicationInitialization> </system.webServer> 
  5. Recycle app pool 回收应用程序池

  6. Check that the app initialized. 检查应用已初始化。

The thing I would like to point out is that the initialization page is relative to the application NOT to the root of the website/domain so if my absolute path is 我想指出的是,初始化页面是相对于应用程序而不是网站/域的根,所以如果我的绝对路径是

domain.com/path1/path2/Service.svc

I would not include /path1/path2 in the initializationPage parameter. 我不会在initializationPage参数中包含/path1/path2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM