Working with HttpHandler in IIS 7

SheoNarayan
Posted by in ASP.NET category on for Intermediate level | Views : 36233 red flag

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.
Introduction

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.

First way

The first way is by going through Wizard in IIS. Lets see how to do that.

  1. First open your IIS 7.
  2. Got to your website
  3. Open Handler Mappings by double clicking it.
  4. Click Add Managed Handlers ... from Action pane (right side), you should see your screen something like Picture - 1 below.
  5. Write Request Path
  6. Write Type of the handler you want to use for the requested path
  7. Write Name of this handler for identification purpose.
  8. 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

<system.webServer>

<handlers>

<add name="MyCustomHanlder" path="/mypage/mypage*.aspx" verb="*" type="MyHanlder.CustomHttpHanlder" resourceType="Unspecified" preCondition="integratedMode" />

</handlers>

<system.webServer>

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.

Second way

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 !!!

Page copy protected against web site content infringement by Copyscape

About the Author

SheoNarayan
Full Name: Sheo Narayan
Member Level: HonoraryPlatinum
Member Status: Administrator
Member Since: 7/8/2008 6:32:14 PM
Country: India
Regards, Sheo Narayan http://www.dotnetfunda.com
http://www.snarayan.com
Ex-Microsoft MVP, Author, Writer, Mentor & architecting applications since year 2001. Connect me on http://www.facebook.com/sheo.narayan | https://twitter.com/sheonarayan | http://www.linkedin.com/in/sheonarayan

Login to vote for this post.

Comments or Responses

Posted by: Abhijit Jana on: 1/1/2009
This is fantastic article Sheo. Good Job !! I had worked in IIS 7.0 for my last project Production deployment. There is huge change in IIS 6.0 and IIS 7.0 Architecture. I have written a complete article on IIS 7.0.
http://www.codeproject.com/KB/aspnet/IIS7ASPNet.aspx
Hop you will also like it.

Cheers !!
Abhijit

Posted by: SheoNarayan on: 1/1/2009
Thanks Abhijit,

I saw your article and I must appreciate your effort you have put in that article.

It's wonderful. Keep it up!!!

--
Thanks,
Sheo Narayan
Posted by: Chandrakanth on: 3/15/2012 | Points: 25
Hi...
Sheo Sir..

HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

I am getting this kind error when I was browse that page

Login to post response

Comment using Facebook(Author doesn't get notification)