设为首页 收藏本站
查看: 435|回复: 0

[经验分享] Creating portable ASP.NET applications that work on IIS 6.0, IIS 7.0 Classic, an

[复制链接]

尚未签到

发表于 2015-8-15 10:20:26 | 显示全部楼层 |阅读模式
ASP.NET applications in IIS 7.0 Integrated mode requires configuration changes if they define custom modules or handlers. The primary changes involve moving the module and handler configuration from the ASP.NET&#8217;s <httpModules> and <httpHandlers> sections to the IIS 7.0 <modules> and <handlers> sections used by the Integrated pipeline.

However, <modules> and <handlers> are not recognized on down-level platforms, such as IIS 6.0. They are also isn&#8217;t supported in Classic mode on IIS 7.0.

For applications that need to work in both IIS 7.0 Integrated mode, and IIS 7.0 Classic mode or previous versions of IIS, this raises the question of whether two different versions of the application are needed to allow this.

In fact, it is possible to create portable ASP.NET applications that can function in all three environments without configuration changes.

The design of the configuration specifically allows this to happen, by specifying both sets of configuration concurrently. Depending on the mode the application is in, the right set of configuration is selected to determine the modules and handlers for the application.

Let&#8217;s take a look at such a configuration for an application that adds a module and a handler:

  <configuration>
    <system.web>
      <!-- Modules for IIS 6.0 and IIS 7.0 Classic mode -->
      <httpModules>
          <add name="MyModule" type="MyApp.MyModule" />
      </httpModules>
  
      <!-- Handlers for IIS 6.0 and IIS 7.0 Classic mode -->   
      <httpHandlers>
        <add path="*.myh" verb="GET" type="MyApp.MyHandler" />
      </httpHandlers>        
    </system.web>
  
    <system.webServer>
      <!-- Modules for IIS 7.0 Integrated mode -->
      <modules>
        <add name="MyModule" type="MyApp.MyModule" />      
      </modules>
  
      <!-- Handlers for IIS 7.0 Integrated mode -->   
      <handlers>
        <add name="MyHandler" path="*.myh" verb="GET" type="MyApp.MyHandler" preCondition="integratedMode" />
          
      </handlers>
  
      <!-- Disable detection of IIS 6.0 / Classic mode ASP.NET configuration -->   
      <validation validateIntegratedModeConfiguration="false" />
    </system.webServer>
  </configuration>

The things to notice here are:
1)       The module and handler are first configured in the ASP.NET <httpModules> and <httpHandlers> sections, precisely the way you would do it for an ASP.NET application running on IIS 6.0, or running in Classic mode on IIS 7.0.
2)       The module and handler are then configured in the IIS 7.0 <modules> and <handlers> sections. This enables them to be recognized by IIS 7.0 in Integrated mode.
3)       The validateIntegratedModeConfiguration attribute in the <validation> section is used to disable runtime rejection of Integrated mode applications that have legacy ASP.NET settings, which we do have.

In fact, this configuration is exactly what is generated by default when you use the AppCmd Migrate Config command on your ASP.NET application for the first time. The migration logic creates the migrated configuration needed for IIS 7.0 Integrated mode, and keeps your old configuration if you ever want to take the app to Classic mode or to down-level versions of IIS.

Now, the dangerous thing here is that after migration, the server will no longer complain about the presence of the legacy ASP.NET configuration. Even if it gets out of sync with your Integrated mode configuration &#8211; for example, if you add a module to <httpModules>, but not to <modules>, that module will run in Classic mode but not in Integrated mode.

Because of this, it is your responsibility to make sure that any changes made to the Classic configuration set are also made to the Integrated configuration set, and visa versa.

To understand this further, let&#8217;s see what happens when this application is deployed to the IIS 7.0 Integrated mode, Classic mode, and IIS 6.0:

IIS 7.0 Integrated mode: ASP.NET modules and handlers are loaded from the combined <modules> and <handlers> configuration sections.  ASP.NET&#8217;s <httpModules> and <httpHandlers> sections are ignored, and no error is generated because we disabled validation.

IIS 7.0 Classic mode: ASP.NET modules and handlers are loaded from the <httpModules> and <httpHandlers> configuration sections. Managed modules in <modules> are ignored, and the managed handlers in the <handlers> section are preconditioned away.

IIS 6.0: ASP.NET modules and handlers are loaded from the <httpModules> and <httpHandlers> configuration sections. IIS 6.0 has no knowledge of the <handlers> and <modules> sections, and ASP.NET 2.0 does not complain because the entire <system.webServer> section group is registered with an &#8220;IgnoreSectionHandler&#8221; (ASP.NET 1.1 doesn&#8217;t have this, so you need to manually do this).

NOTE that in the IIS 7.0 Classic mode, and on down-level versions of IIS, you will also need to add a script map mapping the MYH extension to ASP.NET 2.0, in order for your handler mapping to take effect. On IIS 7.0, this will actually produce another <handlers> entry in the web.config file as follows:

        <add name="MyHandler-Classic" path="*.myh" verb="GET" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2
  .0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness3
  2" responseBufferLimit="0" />   

On IIS 6.0 and below, it will add a script map entry to the scriptmaps metabase property for the application.

Because this is a different step for IIS 7.0 vs. IIS 6.0 and earlier servers, I do not include this configuration in the portable web.config, but rather create it as an additional step. If you just want portability between Integrated and Classic mode, you can add the entry above to your portable web.config (NOTE that the automatic migration also does not produce this entry).

Finally I should note that in many cases, ASP.NET modules in Integrated mode perform tasks that are only possible in Integrated mode applications. After all, if Classic mode was the same as Integrated, what would be the point of going through all this pain of having two modes?

In those cases, these modules may need to be registered only in the Integrated configuration set. Or, they may necessitate two versions of the application, one with fewer features for Classic mode and another with the full feature set for Integrated mode.

This should make it easier to produce ASP.NET applications for Integrated mode that require to work on multiple platforms. In a future post, I'll cover development tricks you can use to develop modules that work in both modes.

Thanks,

Mike

转自:http://mvolo.com/blogs/serverside/archive/2008/04/15/Creating-portable-ASP.NET-applications-that-work-on-IIS-6.0_2C00_-IIS-7.0-Classic_2C00_-and-IIS-7.0-Integrated-modes.aspx

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-99243-1-1.html 上篇帖子: c#操作IIS 下篇帖子: 64位操作系统下IIS报“试图加载格式不正确的程序”错误(转)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表