In order to use custom HttpHandler in IIS 6 we simply used to write <httpHandlers> tag inside System.web tag in web.config file but in IIS 7 it is little tricky. In this article, I am going to show how to configure custom HttpHanlder in IIS 7.
If you had used Custom HttpHandler in your application that was hosted on IIS 6 or on Windows XP system and have shifted to IIS 7 or Vista now, your HttpHanlder will not work. You will have to do a little trick in your web.config file either manually or through IIS 7. (To know more about how to write Custom HttpHanlder to form SEO friendly url, visit http://www.dotnetfunda.com/articles/article75.aspx )
Configuring Custom HttpHanlder in IIS 7
There are two ways you can configure your Custom HttpHandler in IIS 7.
The first way is by going through Wizard in IIS. Lets see how to do that.
- First open your IIS 7.
- Got to your website
- Open Handler Mappings by double clicking it.
- Click Add Managed Handlers ... from Action pane (right side), you should see your screen something like Picture - 1 below.
- Write Request Path
- Write Type of the handler you want to use for the requested path
- Write Name of this handler for identification purpose.
- Click OK
Picture - 1
As soon as you will click OK, you can notice that your application web.config file has been changed. In my case my code inside web.config file looks like following
<add name="MyCustomHanlder" path="/mypage/mypage*.aspx" verb="*" type="MyHanlder.CustomHttpHanlder" resourceType="Unspecified" preCondition="integratedMode" /></handlers>
Notice that earlier we used to write handlers inside <system.web> > <httpHandlers> but here it is written in <system.webServer> > <handlers>. Once your web.config file has been modified, you are done. Now simply test it. Try any url like http://localhost/mypage/mypageWHATEVER.aspx (in my case) and you will see that your hanlder is working now.
The second way is very easy, simply copy the code of the hanlder you just added and modify their corresponding attributes and place inside <handlers> and it will work. So there is no need to go to IIS every time to add new handlers.
Hope you liked this small but useful article.
Thanks and keep reading !!!