3

I know that if I want to have requests for MyPage.aspx go to the class called MyHandler in the assembly called MyAssembly, I can add this to my web.config file:

<configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" path="MyPage.aspx" type="MyHandler, MyAssembly"/>
  </system.web>
</configuration>

This works for any MyPage.aspx at the (made up) URL: www.mycoolsite.com/MyProject/[SomePathHere]/MyPage.aspx

What if I want to do it for every MyPage.aspx except www.mycoolsite.com/MyProject/NoHandler/MyPage.aspx

Is there a way to exclude that path from the handler?

Tim Goodman
  • 23,308
  • 7
  • 64
  • 83

1 Answers1

7

You can put a web.config in the NoHandler folder that defines a different handler (NotFound if you want to server a 404 style, etc). Same format as your current web.config, just put only the elements you want to override like the handler.

Here's an example if you want to override with a 404 in that directory:

<configuration>
 <system.web>
  <httpHandlers>
   <remove verb="*" path="MyPage.aspx" type="MyHandler, MyAssembly"/>
   <add verb="*" path="MyPage.aspx" type="MySpecialHandler, MyAssembly"/>
  </httpHandlers>
 </system.web>
</configuration>
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • If something matches both paths what determines priority? I mean, am I guaranteed that `` would win out over `` – Tim Goodman Mar 24 '10 at 17:12
  • @Tim - Updated the answer with an example, there's also a remove option you can use for your case :) – Nick Craver Mar 24 '10 at 17:15
  • Thanks for the help, Nick. This solution worked for me, except that I had to take out the "type" from the remove ... otherwise it was giving me an error. – Tim Goodman Mar 24 '10 at 18:02