原文

代码 或者点

通过IIS 8.0应用初始化特性管理员可以配置IIS为一个网站或多个网站提前执行初始化任务。当应用在初始化期间,可以通过配置先返回一个静态页面知道应用的初始化任务完成。

通过配置一系列的全局级和应用级规则可以控制如何/何时初始化网站应用。

指南

事前准备

首先需要安装IIS 8.0。另外,应用初始化特性是作为IIS的"Application Development"子特性提供的,也需要安装。

下面的截图来自于Windows Server 2012 Server Manager UI,展示了如何安装Application Initialization特性

全局应用初始化

可以在两个地方配置应用初始化特性:全局级别的applicationHost.config文件,和应用级别的web.config文件。

In this walkthrough, you will configure a sample application to always be initialized when the application pool associated with the application starts up. Since application pool behaviors can only be configured in applicationHost.config, running application initialization whenever an application pool starts up is considered part of the "global" application initialization settings.

修改applicationHost.config

用记事本打开%WINDIR%\system32\inetsrv\config文件夹中的applicationHost.config文件。

找到配置块,找到名为".NET v4.5"的应用池记录。

修改这个应用池记录让这个应用池是always running的状态。

<add name=".NET v4.5" startMode="AlwaysRunning" managedRuntimeVersion="v4.0" />

往下找到配置元素。在配置元素中有一个

<application path="/appinit" preloadEnabled="true" applicationPool=".NET v4.5">

设置preloadEnable为true tells IIS 8.0 that it sends a "fake" request to the application when the associated application pool starts up. That is why in the previous step we set the application pool's startMode to "AlwaysRunning".

With the combination of the application pool always running, and the application itself being marked to always receive a fake request, whenever the machine restarts and/or the World Wide Web service is recycled, IIS 8.0 ensures that the application pool instance is running and that the application "/appinit" is always sent a fake request to trigger the application to start up.

修改web.config

用记事本打开位于网站所在目录C:\inetpub\wwwroot\appinit中的web.config。

web.config已经设置好了一些section,但是被注释了,先取消<system.webServer>中的注释。

<applicationInitialization
remapManagedRequestsTo="Startup.htm"
skipManagedModules="true" >
<add initializationPage="/default.aspx" />
</applicationInitialization>

这个配置告诉IIS在初始化完成前,返回Startup.html页面给所有请求者。

运行应用

net stop w3svc & net start w3svc

用浏览器打开http://localhost/appinit/default.aspx

浏览器先是显示“Startup.htm”这个页面,一旦应用初始化完成,便会返回真正的请求页面。

配置overlapped进程回收

IIS 8.0通过在一个后台overlapped进程中执行应用初始化集成了应用初始化和overplapped进程回收。当IIS检查到一个活动的工作进程在被回收的时候,不会马上转到新的工作进程中,而是等新的进程完成了初始化工作后才转到这个新的进程。这样保证了当应用已经在运行的时候不会再次看到“Startup.html”页面。

打开applicationHost.config文件。修改如下:

<add name=".NET v4.5"
startMode="AlwaysRunning"
managedRuntimeVersion="v4.0" >
<recycling logEventOnRecycle="Schedule">
<periodicRestart requests="30" />
</recycling>
</add>

元素告诉IIS每30个HTTP请求回收进程。

运行应用

net stop w3svc & net start w3svc

用浏览器打开http://localhost/appinit/default.aspx

“Startup.htm”展现出来了

打开任务管理器。按照进程名排序,可以看到有一个w3wp.exe线程,状态为Running。这个就是在运行"appinit"应用的进程。

不断刷新浏览器直到出现了真正的default.aspx页面。

现在再次刷新页面30次以上,导致IIS回收应用池。现在停止刷新,回到任务管理器,可以看到出现了第二个w3wp.exe进程:



上面的截图告诉我们当进程开始回收的时候第二个w3wp.exe开始了。

再次刷新浏览器,我们看到的依然是default.aspx页面。即使应用初始化正在这个新的w3wp.exe实例中进行。

URL Rewrite与应用初始化

[译]IIS 8.0应用初始化的更多相关文章

  1. ASP.NET的运行原理与运行机制 如何:为 IIS 7.0 配置 <system.webServer> 节

    https://technet.microsoft.com/zh-cn/sysinternals/bb763179.aspx 当一个HTTP请求到服务器并被IIS接收到之后,IIS首先通过客户端请求的 ...

  2. IIS 7.0 的 ASP.NET 应用程序生命周期概述(转载)

    IIS 7.0 的 ASP.NET 应用程序生命周期概述更新:2007 年 11 月本主题介绍在 IIS 7.0 集成模式下运行以及与 IIS 7.0 或更高版本一起运行的 ASP.NET 应用程序的 ...

  3. IIS 5.0 和 6.0 的 ASP.NET 应用程序生命周期概述

    本主题概述 ASP.NET 应用程序的生命周期,列出了重要的生命周期事件,并描述了您编写的代码将如何适应于应用程序生命周期.本主题中的信息适用于 IIS 5.0 和 IIS 6.0.有关 IIS 7. ...

  4. Intelligencia.UrlRewriter在IIS 7.0下的完全配置攻略

    在项目中,之前公司是使用IIS 7.0官方的URL重写模块,官方的使用说明请参见官方URLRewrite  ,添加伪静态支持,后来经理问我有没有涉及伪静态,我说之前项目中我一直是用Intelligen ...

  5. 在Windows 2008/2008 R2 上配置IIS 7.0/7.5 故障转移集群

    本文主要是从:http://support.microsoft.com/kb/970759/zh-cn,直接转载,稍作修改裁剪而来,其中红色粗体部分,是我特别要说明的 若要配置 IIS 7.0 和 7 ...

  6. IIS 7.0 下 httpMoudle 失效的问题

    在web.config里配置了: <system.web> <httpModules>  <add type="DevExpress.Web.ASPxClass ...

  7. ASP.NET MVC3 系列教程 - 部署你的WEB应用到IIS 6.0

    I:ASP.NET MVC3 部署的前期工作 1.确认部署的服务器操作系统环境 首先我们确认服务器的操作系统版本 可以从系统命令行工具里输入: systeminfo 获取相关操作系统信息例如 然后再确 ...

  8. IIS 7.0 and Web Farms

    1. IIS 6 IIS 6.0 was capable of scaling out to virtually any number of web servers and had tools lik ...

  9. 使用IIS 7.0 Smooth Streaming 优化视频服务

    http://www.cnblogs.com/dudu/archive/2013/06/08/iis_webserver_settings.html (支持高并发的IIS Web服务器常用设置) ht ...

随机推荐

  1. auto_clipboard

    黄山松发表于博客园:http://www.cnblogs.com/tomview/p/6137179.html #ifndef __HSS_AUTO_CLIPBOARD_HSS__#define __ ...

  2. 使用gulp-uncss清理多余无用css

    cnpm 也可以使用npm cnpm install gulp-uncss --save-dev gulpfile.js var gulp = require('gulp'), uncss = req ...

  3. 跳跃的舞者,舞蹈链(Dancing Links)算法——求解精确覆盖问题

    精确覆盖问题的定义:给定一个由0-1组成的矩阵,是否能找到一个行的集合,使得集合中每一列都恰好包含一个1 例如:如下的矩阵 就包含了这样一个集合(第1.4.5行) 如何利用给定的矩阵求出相应的行的集合 ...

  4. Vue.js的入门

    介绍 vue.js 是一个客户端js库,可以用来开发单页应用.为了一个项目的选型,我前前后后的看了angular.react.vuejs ,对前两者是佩服,对后者是爱.因为它简洁干净利索,并且还有高大 ...

  5. ubuntu源笔记

    比如说清华大学的ipv6镜像源:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/ /etc/apt/sources.list为包管理工具apt的软件包 ...

  6. Class.forName和ClassLoader.loadClass等

    Class类 首先,Class类里可以记载所有类的属性.方法等信息.这个也就是运行时类别标记,它记录了所有的对象(比如int,MyClass,void,数组等等)对应的类信息. Class对象 JVM ...

  7. [LeetCode] Total Hamming Distance 全部汉明距离

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  8. [LeetCode] Count The Repetitions 计数重复个数

    Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc&qu ...

  9. 打包SpringBoot工程并部署

    使用工具:Eclipse Linux下JDK版本:jdk-7u79-linux-x64.tar.gz 一.打包成jar并部署 步骤如下: 首先上pom.xml: <project xmlns=& ...

  10. logback logback.xml常用配置详解 <filter>

    <filter>: 过滤器,执行一个过滤器会有返回个枚举值,即DENY,NEUTRAL,ACCEPT其中之一.返回DENY,日志将立即被抛弃不再经过其他过滤器:返回NEUTRAL,有序列表 ...