Migration of ASP.NET app from IIS6 to IIS7 (7.5)
For many of us familiar problem. You developing applications under IIS6 and you're about to move them to IIS7. In previous version of IIS was enough to copy over your files, create app pool and site. IIS7 (7.5) is different in this point.
In IIS6 there was only one way hot to extend server with other features – using ISAPI filters. Whole .NET is lived within one dll aspnet_isapi.dll. If the request was for files with .NET type extensions (such .aspx, .ashx, .axd and so on) your application know them and was able to serve them. If request was for file with extension for example .jpg or other static file, the application was not aware about them. For example this is the reason why URL authorization does not work for static files.
IIS7 offers two modes of work:
- Classic – In IIS requests are processed by above description. Basically the system is compatible with previous versions of IIS
- Integrated – the default one. In this mode has IIS privileged position, the HTTP handlers and modules (known from ASP.NET) can be executed directly. They are in line with ISAPI filters and built-in IIS functionality.
HTTP handlers, modules were not changed at all, so you don't need to rewrite or recompile them. But was has been changed is the way how to know IIS about which handler, module to use. Basically this is often problem when app is running properly under IIS6 but won't under IIS7. This is not such difference between IISs but it's big difference between Classic and Integrated mode on application pool. You have two options:
- Put your application under Classic managed pool (this is not recommended, use it only in case when other solutions fails)
- Change the registration of modules and handlers in web.config file to reflect newest configuration schema.
There is no difference whether you register handler or module under IIS6 or IIS7 Classic Mode. Illustration of its registration in web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*My.axd" type="MyHttpHandler"/>
</httpHandlers>
<httpModules>
<add name="MyModule" type="MyHttpModule"/>
</httpModules>
</system.web>
</configuration>
In case of web.config in II7 Integration mode, registration will looks like:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<handlers>
<add name="NameOfMyHandler" verb="*" path="*My.axd" type="MyHttpHandler"/>
</handlers>
<modules>
<add name="MyModule" type="MyHttpModule" preCondition="managedHandler"/>
</modules>
</system.webServer>
</configuration>
Generally you have to perform these changes:
- you need rename httpHandlers to handlers and httpModules to modules.
- Handlers has required attribute name, so you have to name them
- Modules should have attribute preCondition with value managedHandler. This is optional and depends on behavior of particular module (module will called only in case when its execution will be driven by handler written in .NET).
Changes can be done manually or by command line tool (see bellow).
HTTP modules are called for each request. In case of II6 or Classic mode it means for each request mapped in aspnet_isapi.dll configuration. For integrated mode it means for all request including for static files.
Well sometimes you run into problem when you your app needs to work IIS6 as well IIS7. Problem is once you register handlers and module in system.webServer section you need to remove their registration from system.web section. If the IIS would ignore old registration insystem.web section I could be security risk caused by not executed some modules, handlers. Mostly those for authentication and authorization. But there is am option how to avoid this checking and allow to have registrations in both sections. All you need to do is to turn off validation by attribute validateIntegratedModeConfiguration. Using this attribute is not really recommended.
So the universal web.config for both scenarios would looks like:
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*My.axd" type="MyHttpHandler"/>
</httpHandlers>
<httpModules>
<add name="MyModule" type="MyHttpModule" />
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<add name="NameOfMyHandler" verb="*" path="*My.axd" type="MyHttpHandler"/>
</handlers>
<modules>
<add name="MyModule" type="MyHttpModule" preCondition="managedHandler"/>
</modules>
</system.webServer>
</configuration>
Instead of modifying web.config manually, you can perform required changes from command line by
%windir%\system32\inetsrv\Appcmd migrate config "<ApplicationPath>"
ApplicationPath is the virtual path of the application containing the site name, such as "Default Web Site/app1" or site name map in IIS, for example Default Web Site.
The tool will modify web.config in order to move registration of handlers, modules fromsystem.web to system.webServer section.
Migate the web.config of Application, run the migration command as below.
C:\> %systemroot%\system32\inetsrv\APPCMD.EXE migrate config "Default Web Site/app1"
Successfully migrated section "system.web/httpModules".
Successfully migrated section "system.web/httpHandlers".
If you are going to migate the web.config of Site, don’t miss a forward slash ("/") after the domain name.
C:\> %systemroot%\system32\inetsrv\APPCMD.EXE migrate config "Default Web Site/"
Successfully migrated section "system.web/httpModules".
Successfully migrated section "system.web/httpHandlers".
Otherwise you may get an error like below,
ERROR ( message:Cannot find APP object with identifier “Default Web Site”. )
Even you've did web.config changes you app can still failing under Integration mode. The most common is "Request is not available in this context" exception. This happens when your implementation is about to access Request object in Application_Start method of global.asaxfile. Error is due to design change in the II7 Integrated pipeline that makes Request object unavailable in Application_Start. The Classic mode has no problems with it. What you can do about it is to change your app to avoid reference to Request context inside Application_Startor running app under Classic mode (not recommended). More about avoiding reference to Request object you can find on Mike Volodarsky's blog.
Migration of ASP.NET app from IIS6 to IIS7 (7.5)的更多相关文章
- ASP.NET程序从IIS6移植到IIS7时出现500.22错误
最可能的原因: • 此应用程序在 system.web/httpModules 节中定义配置. 可尝试的操作: • 将配置迁移到 system.webServer/modules 节 ...
- ASP.NET程序从IIS6移植到IIS7时出现500.22错误(转)
最可能的原因: • 此应用程序在 system.web/httpModules 节中定义配置. 可尝试的操作: • 将配置迁移到 system.webServer/modules 节.也可 ...
- 如何将ASP.NET-WebApi发布到IIS6.0上(转)
关于"如何将ASP.NET-WebApi发布到IIS6.0上"的这方面的学习,一开始项目组长让我们接触的时候,我的心情是这样的 哇呜.jpg 当时真的是一脸懵逼啊,对于刚接触asp ...
- IIS6.0 IIS7.5应用程序池自动停止的解决方法
前边提到由win2003升级到win2008 server r2 64位系统,然后用了几个小时配置IIS7.5+PHP+MYSQL等的环境,先是遇到IIS7.5下PHP访问慢的问题,解决之后又出了新的 ...
- IIS6.0 IIS7.5应用程序池自动停止的解决方法 搜集整理
来源:http://www.guchengnet.com/1499.html IIS6.0 IIS7.5应用程序池自动停止的解决方法 搜集整理 发表于2016年12月14日 有2.3个月没有用本地的i ...
- IIS6与IIS7在编程实现HTTPS绑定时的细微差别
本文章其实最主要信息是: 问题出在那个小小的*号上——IIS6中不支持通配符,第一部分为空时表示(All Unsigned),而IIS7中同时支持空或通配符的写法,如果为空则自动转为*:443:,我们 ...
- IIS6、IIS7.5设置网站默认首页方法(Directory Listing Denied)
这篇文章主要介绍了IIS6.IIS7.5设置网站默认首页方法,如果不设置访问目录就会提示Directory Listing Denied,就是不允许列出文档,为了安全网站都会设置不设置默认,需要的朋友 ...
- Asp.net APP 重置密码的方式
在开发ASP.NET WEB APP的时候,时间长了容易忘记最初设置的密码,即使打开数据库也不好重置,因为密码都是加密存储在数据库中的.下面是几种通过代码重置密码的方式: 第一种: string re ...
- 关于ASP.NET MVC4在IIS6中不认识安卓移动设备的解决办法
在IIS7中发现安卓的手机浏览器是可以跳转滴. 项目中是采用***.mobile.cshtml来显示移动视图的. 部署到IIS6.0中发现并没有转到*.mobile.cshtml移动视图. 进过漫长的 ...
随机推荐
- [转贴]JAVA:RESTLET开发实例(三)基于spring的REST服务
前面两篇文章,我们介绍了基于JAX-RS的REST服务以及Application的Rest服务.这里将介绍restlet如何整合spring框架进行开发.Spring 是一个开源框架,是为了解决企业应 ...
- Linux守护进程daemon
守护进程,也就是通常说的Daemon进程,是Linux中的后台服务进程.它是一个生存期较长的进程,通常独立于控制终端并且周期性地执行某种任务或等待处理某些发生的事件.守护进程常常在系统引导装入时启 ...
- WC2015 滚粗记
Day 0 和南师附中诸人去杭州,想到这是第三次去杭州有点感动 想到noi还要在杭州,简直…… 火车站接送好评如潮 ym大学军,到学军领资料然后到浙大宿舍安顿,noi的书包还是挺不错的 看起来宿舍还可 ...
- Mac 把图片反色
黑色图变白色 1:用预览打开 2:打开"调整颜色" 3:把"自动色阶"两边的按钮, 拖动换位置,就可以看到效果了.
- 系统交易策略 hylt
最令我尴尬的事情,莫过于很多朋友来到网站,不知道我说的是什么.大多数人以为鬼仆是推销软件的.其实这里理解是错的,特别是一些软件制作与经销商,更出 于推销的目的,故意夸大产品性能,模糊交易系统与一般行情 ...
- 畅通工程续 HDOJ--1874
畅通工程续 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submiss ...
- Ext.form.FormPanel定义的参数说明
1.formId : String (可选的)FORM标签的id(默认是自动生成的). 2.labelWidth : Number 标签的宽度.该属性级联于子容器. 3. itemCls : Stri ...
- java常用重构优化总结--自己亲身体验
代码重构 6大原则: 单一职责原则(一个类最好最好只有一种行为动机,太多承担职责会导致耦合度太高). 开放封闭原则(功能可以扩展,但是不可以内部修改). 依赖倒转原则(应该依赖抽象 ...
- HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)
此题无法用JavaAC,不相信的可以去HD1029题试下! Problem Description "OK, you are not too bad, em- But you can nev ...
- [CODEVS1220]数字三角形
题目描述 Description 如图所示的数字三角形,从顶部出发,在每一结点可以选择向左走或得向右走,一直走到底层,要求找出一条路径,使路径上的值最大. 输入描述 Input Description ...