如何:为 IIS 7.0 配置 <system.webServer> 节
https://technet.microsoft.com/zh-cn/sysinternals/bb763179.aspx
https://www.cnblogs.com/tl2f/p/5016154.html
Web.config 文件中的 system.webServer 节用于指定适用于 Web 应用程序的 IIS 7.0 设置。system.WebServer 是 configuration 节的子级。有关更多信息,请参见 IIS 7.0: system.webServer Section Group (IIS Settings Schema)(IIS 7.0:system.webServer 节组(IIS 设置架构))。
下面是可以在 system.WebServer 配置组中进行的 Web 服务器设置的示例:
当请求未包含特定资源时,Web 服务器返回给客户端的默认文档(defaultDocument 元素)。
响应的压缩设置(httpCompression 元素)。
自定义标头(httpProtocol 节的 customHeaders 元素)。
模块(modules 元素)。
处理程序(handlers 元素)。
system.webServer 节中的某些设置只适用于 IIS 7.0 集成模式,而不适用于经典模式。具体而言,如果应用程序正在经典模式下运行,则会忽略 Web.config 文件的 system.WebServer节中指定的所有托管代码模块和处理程序。与 IIS 的早期版本相同,托管代码模块和处理程序必须在 system.web 节的 httpModules 和 httpHandlers 元素中定义。
本主题阐释需要修改 system.webServer 节的三个常见配置任务:
添加默认文件,以便在请求 URL 未包含特定的文件时,提供该默认文件。
注册托管代码模块。
添加自定义响应标头。
当请求 URL 未包含 Web 应用程序的特定文件时,IIS 7.0 将提供一个默认文件。
配置默认文件
如果应用程序没有 Web.config 文件,请使用 Visual Studio 或文本编辑器创建该文件。
有关更多信息,请参见 编辑 ASP.NET 配置文件。
如果 Web.config 文件尚未包含 system.webServer 节,请在 configuration 元素中创建该节,如下面的示例所示:
<configuration>
<system.webServer>
</system.webServer>
</configuration>在 system.webServer 元素内,创建一个 defaultDocument 元素。
在 defaultDocument 元素内,创建一个 files 元素。
在 files 元素内创建一个 add 元素,并在 value 属性内指定默认文件的路径和名称。
下面的示例演示了一个 system.webServer 节,该节配置为提供 Products.aspx 文件作为默认文件。
<configuration>
<system.webServer>
<defaultDocument> <files> <add value="Products.aspx" /> </files> </defaultDocument>
</system.webServer>
</configuration>
每次请求时都会调用托管代码模块,通过该模块可对请求或响应进行自定义。
配置自定义托管代码模块
如果应用程序没有 Web.config 文件,请使用 Visual Studio 或文本编辑器创建该文件。
有关更多信息,请参见 编辑 ASP.NET 配置文件。
如果 Web.config 文件尚未包含 system.webServer 节,请在 configuration 元素中创建该节,如下面的示例所示:
<configuration>
<system.webServer>
</system.webServer>
</configuration>在 system.webServer 元素内,创建一个 modules 元素。
在 modules 元素内创建一个 add 元素,并在 name 和 type 属性中指定自定义模块。
实际的名称和类型取决于要添加的模块。下面的示例演示如何添加名为CustomModule的自定义模块,该模块将实现为类型Samples.CustomModule。
<configuration>
<system.webServer>
<modules> <add name="CustomModule" type="Samples.CustomModule" /> </modules>
</system.webServer>
</configuration>向模块注册中添加 precondition 属性,并将其值设置为managedHandler。
此前置条件会导致仅在请求 ASP.NET 应用程序资源(例如 .aspx 文件或托管处理程序)时才调用该模块。该资源中不包括静态文件(例如 .htm 文件)。
其 configuration 节将类似于以下示例。
<configuration>
<system.webServer>
<modules>
<add name="CustomModule" type="Samples.CustomModule"
precondition="managedHandler" />
</modules>
<defaultDocument>
<files>
<add value="Products.aspx" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
利用自定义响应标头,可向浏览器发送应用程序特定的信息。例如,可以添加 Content-Language 标头来描述网页正文中使用的语言。若要执行此操作,请提供一个或多个语言和国家/地区值,例如 en-US(美国英语)或 en-GB(英国英语)。
配置自定义响应标头
如果应用程序没有 Web.config 文件,请使用 Visual Studio 或文本编辑器创建该文件。
有关更多信息,请参见 编辑 ASP.NET 配置文件。
如果 Web.config 文件尚未包含 system.webServer 节,请在 configuration 元素中创建该节,如下面的示例所示:
<configuration>
<system.webServer>
</system.webServer>
</configuration>在 system.webServer 元素内,创建一个 httpProtocol 元素。
在 httpProtocol 元素内,创建一个 customHeaders 元素。
在 customHeaders 元素内创建一个 add 标记,并在 name 和 value 属性中指定自定义标头。
实际的名称和类型将取决于该标头在应用程序中的功能。下面的示例演示如何添加名为CustomHeader且值为CustomHeader的自定义标头。
<configuration>
<system.webServer>
<httpProtocol> <customHeaders> <add name="CustomHeader" value="CustomHeader" /> <customHeaders> </httpProtocol>
</system.webServer>
</configuration>
任务
概念
参考
当你有自定义的HttpModule和HttpHandler时,需要同时在这两处添加
这个是为IIS6或者IIS7的经典模式用的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
< system.web > < httpHandlers > < remove verb="*" path="*.asmx"/> < add verb="*" path="CombineScriptHandler.aspx" validate="false" type="MvcScriptManager.CombineScriptHandler, MvcScriptManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6eb4f344e8972dc6"/> < add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> < add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> < add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/> < add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </ httpHandlers > < httpModules > < add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> < add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </ httpModules > </ system.web > |
这个是为IIS7的集成模式用的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
< system.webServer > < validation validateIntegratedModeConfiguration="false"/> < modules runAllManagedModulesForAllRequests="true"> < remove name="ScriptModule"/> < remove name="UrlRoutingModule"/> < add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> < add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </ modules > < handlers > < remove name="WebServiceHandlerFactory-Integrated"/> < remove name="ScriptHandlerFactory"/> < remove name="ScriptHandlerFactoryAppServices"/> < remove name="ScriptResource"/> < remove name="MvcHttpHandler"/> < remove name="UrlRoutingHandler"/> < add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> < add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> < add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> < add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> < add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> </ handlers > </ system.webServer > |
在Web.config中配置handler节点时发现用vs2010和用vs2015竟然不一样,经过多次测试发现了一些倪端:
<configuration>
<!--vs2010中需要配这个,vs2015中可省开始-->
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpHandlers>
<add path="user.ashx(ajax中url请求的路径)" verb="POST,GET" type="MyHandler.UsersHander(方法的真实路径即:MyHandler类库下的UsersHander类)"/>
</httpHandlers>
</system.web>
<!--vs2010中需要配这个,vs2015中可省结束-->
<!--vs2015中需要配这个,vs2010中可省开始-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false" /><!--没有上面内容时此处可省-->
<handlers>
<add path="user.ashx(ajax中url请求的路径)" verb="POST,GET" type="MyHandler.UsersHander(方法的真实路径即:MyHandler类库下的UsersHander类)"/>
</handlers>
</system.webServer>
<!--vs2015中需要配这个,vs2010中可省结束-->
</configuration>
用于健康检测:
namespace HealthCheck.Utils
{
public class HealthCheckHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
} public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("ok");
}
}
}
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="HealthCheck" path="healthcheck.check" type="HealthCheck.Utils.HealthCheckHandler" verb="get"/>
</handlers>
</system.webServer>
将HealthCheck.Utils做成一个类库项目(需要继承IHttpHandler,引入相关引用),生成dll,项目中引入此dll,访问http://localhost:9152/HealthCheck.check 返回
如何:为 IIS 7.0 配置 <system.webServer> 节的更多相关文章
- ASP.NET的运行原理与运行机制 如何:为 IIS 7.0 配置 <system.webServer> 节
https://technet.microsoft.com/zh-cn/sysinternals/bb763179.aspx 当一个HTTP请求到服务器并被IIS接收到之后,IIS首先通过客户端请求的 ...
- 为 IIS 7.0 配置 <system.webServer>
Web.config 文件中的 system.webServer 节用于指定适用于 Web 应用程序的 IIS 7.0 设置.system.WebServer 是 configuration 节的子级 ...
- IIS 4.0配置
neHandler” 今天安装了windows7 开发web项目需要安装IIS,当安装完以后,web程序已经映射到了本地IIS上,运行出现如下错误提示 处理程序“PageHandlerFactor ...
- IIS 7.0 的 ASP.NET 应用程序生命周期概述(转载)
IIS 7.0 的 ASP.NET 应用程序生命周期概述更新:2007 年 11 月本主题介绍在 IIS 7.0 集成模式下运行以及与 IIS 7.0 或更高版本一起运行的 ASP.NET 应用程序的 ...
- 跨域学习笔记3--web.config设置之system.webServer 详细介绍,为网站设置默认文档
自己并不懂,在此先记录下来,留待以后学习... 如何:为 IIS 7.0 配置 <system.webServer> 节2008-06-14 22:26http://technet.mic ...
- 转 web.config设置之system.webServer 详细介绍,为网站设置默认文档
如何:为 IIS 7.0 配置 <system.webServer> 节2008-06-14 22:26http://technet.microsoft.com/zh-cn/sysinte ...
- web.config设置之system.webServer 详细介绍,为网站设置默认文档
如何:为 IIS 7.0 配置 <system.webServer> 节2008-06-14 22:26http://technet.microsoft.com/zh-cn/sysinte ...
- Web.config 文件中的 system.webServer
Web.config 文件中的 system.webServer 节用于指定适用于 Web 应用程序的 IIS 7.0 设置.system.WebServer 是 configuration 节的子级 ...
- Web.config设置system.webServer
一般情况在iis部署web网站都非常顺利,但是遇到复杂环境,或者被配置过又正在使用的时候,就束手无策了, 因为对IIS和Web.config不熟悉,不知其中要害,导致浪费一天甚至更久的时间去处理一个可 ...
随机推荐
- json格式详解
一.Json的简单介绍 从结构上看,所有的数据最终都可以分成三种类型: 第一种类型是scalar(标准变量),也就是一个单独的string(字符串)或数字(numbers),比如“北京”这个单独的 ...
- 每日英语:Tech Firms Flock to Vietnam
Opening up a Korean restaurant among the rice fields and limestone karsts north of Hanoi might seem ...
- C++ 11 Lambda表达式、auto、function、bind、final、override
接触了cocos2dx 3.0,就必须得看C++ 11了.有分享过帖子:[转帖]漫话C++0x(四) —- function, bind和lambda.其实最后的Lambda没太怎么看懂. 看不懂没关 ...
- UBoot启动代码第一阶段流程
http://blog.csdn.net/xautfengzi/article/details/7470134 前段时间了看了UBoot的源码,放了一段时间之后忘得差不多了.现做一些注释,方便以后温习 ...
- 配置maven为阿里云加速
<repositories> <repository> <id>nexus-aliyun</id> <name>Nexus aliyun&l ...
- ajax 和xmlHttpRequest区别
什么是 ajax ajax 即“Asynchronous JavaScript and XML”(异步 JavaScript 和 XML),也就是无刷新数据读取. http 请求 首先需要了解 htt ...
- 【C++程序员学 python】python 之变量
既然学过C++,那么就应该知道变量是什么,常量是什么. python 相比于C++,在使用变量之前不用先声明. 而是直接使用,python 会根据你的变量自动识别其类型. 假如a = 123 那么a ...
- iOS Reachability检测网络状态
一.整体介绍 前面已经介绍了网络访问的NSURLSession.NSURLConnection,还有网页加载有关的webview,基本满足通常的网络相关的开发.其实在网络开发中还有比较常用的就是网络状 ...
- 基于jQuery/CSS3实现拼图效果的相册插件
今天我们要来分享一款很酷的jQuery相册插件,首先相册中的图片会以一定的角度倾斜放置在页面上,点击图片缩略图就可以展开图片,并且图片是由所有缩略图拼接而成,图片展开和收拢的动画效果也非常不错.当然图 ...
- c#简单写售票系统
原理: 先生成一个9行4列的数组,然后用一个输入的值(坐标)去替换掉座位 代码: using System; using System.Collections.Generic; using Syste ...