views:

720

answers:

2

What is the difference of adding and removing handlers in as oppose to ?

In a new web project I made with VS2008, the handlers are defined as this:

<system.web>
        ...

      <httpHandlers>
        <remove verb="*" path="*.asmx"/>
        <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="/hello/helloworld.xml" type="HandlerTest.HelloWorldHandler, HandlerTest"/>
      </httpHandlers>
      <httpModules>
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </httpModules>

    </system.web>

But in a pre-existing project, (ie: Community server), the http handlers are added/removed in as follows:

<system.webServer>
     <validation validateIntegratedModeConfiguration="false"/>
     <security>
      <requestFiltering allowDoubleEscaping="true"/>
     </security>
     <modules runAllManagedModulesForAllRequests="true">
      <remove name="CommunityServer"/>
      <remove name="ScriptModule"/>
      <remove name="UrlRoutingModule"/>
      <add name="CommunityServer" type="CommunityServer.CSHttpModule, CommunityServer.Components"/>
      <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 accessPolicy="Read, Write, Script, Execute">
      <remove name="WebServiceHandlerFactory-Integrated"/>
      <remove name="ScriptHandlerFactory"/>
      <remove name="ScriptHandlerFactoryAppServices"/>
      <remove name="ScriptResource"/>


      <add verb="GET" name="redirect" path="Utility/redirect.aspx" type="CommunityServer.Components.Redirect, CommunityServer.Components"/>
      <add verb="GET" name="aggbug" path="aggbug.aspx" type="CommunityServer.Components.HttpHandler.AggBugHandler, CommunityServer.Components"/>
      <add verb="GET" name="avatar" path="avatar.aspx" type="CommunityServer.Components.HttpHandler.AvatarHttpHandler, CommunityServer.Components"/>
      <add verb="GET" name="vcard" path="vcard.aspx" type="CommunityServer.Components.HttpHandler.VCardHttpHandler, CommunityServer.Components"/>
      <add verb="GET" name="tinyurl" path="r.ashx" type="CommunityServer.Components.HttpHandler.TinyUrlHttpHandler, CommunityServer.Components"/>
      <add verb="GET" name="weblogsubscription-confirmation" path="weblogsubscription-confirmation.ashx" type="CommunityServer.Blogs.Components.WeblogSubscriptionConfirmation, CommunityServer.Blogs"/>
      <add verb="GET" name="threadsubscription-confirmation" path="threadsubscription-confirmation.ashx" type="CommunityServer.Blogs.Components.ThreadSubscriptionConfirmation, CommunityServer.Blogs"/>
      <add verb="GET" name="cfs-file" path="cfs-file.ashx" type="CommunityServer.Components.FileHttpHandler, CommunityServer.Components"/>
      <add verb="GET" name="cfs-filesystemfile" path="cfs-filesystemfile.ashx" type="CommunityServer.Components.FileSystemFileStorageHttpHandler, CommunityServer.Components"/>
      <add verb="GET" name="resized-image" path="resized-image.ashx" type="CommunityServer.Components.ImageFileResizerHttpHandler, CommunityServer.Components"/>
      <add verb="GET,POST" name="multipleupload" path="multipleupload.ashx" type="Telligent.Glow.MultipleUploadFileHandler, Telligent.Glow"/>
      <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" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.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"/>
      <add name="TinyMCE" verb="GET,HEAD,POST" path="TinyMCE.ashx" type="Moxiecode.TinyMCE.Web.HttpHandler,Moxiecode.TinyMCE"/>
      <add name="Schedule" verb="*" path="schedule.ashx" type="CommunityServer.Scheduler.ScheduleHandler, CommunityServer.Scheduler" />
    </handlers>
    </system.webServer>

Why are there more than one way of registering an http handler?

+2  A: 

The <system.web> section applies to IIS6 and below whereas <system.webServer> applies to IIS7 and above. The layout of web.config was re-engineered for IIS7 to make it more powerful / friendly, but at the cost of backwards compatibility.

Chris Shouts
Does that mean that if you want your app to run in both web servers you need to have two web.configs?
flq
+1  A: 

The second example that you posted where they are in the '' node is the way to configure for IIS 7 allowing you to configure the server directly. The other method is "legacy" and works on all supported IIS versions.

Mitchel Sellers