Sunday, October 11, 2009

asp.net - How to add an HttpHandler to replace a folder or page

Lets say you wanted to replace the static config.xml file from a certain folder in your web app with some dynamically served data. For example, custom config xml based on the logged in user's role. This could be done easily with asp.net's httphandlers.
Steps:

  1. create a HttpHandler to serve your data based on who is logged in,
    For example you can use:
    Context.User.Identity.IsAuthenticated
    or Membership.GetUser()
  2. Add that httpHandler to the web.config file and specify the


    <add verb="*" path="MyWebApp1/config.xml" type="MyNS.ConfigXmlHandler" />



  3. Modify the IIS settings for your webapp (here it is MyWebApp1), usually your webapp is located in c:\inetpub\wwwroot\MyWebApp1. Using the IIS management console, find the node for MyWebApp1 and modify its properties. Add an application extension mapping for '.xml', so that the asp.net engine processes it. This way the request for xml files will be routed via the aspnet dll.
  4. asdf
  5. Caveat: Step 1 would be same for all IIS versions, but the other steps would be different based on which IIS you use, basically different from IIS5/6 with IIS7. Configure HttpHandlers in IIS,  Difference between IIS 7 integrated and classic mode
Resources:

No comments:

Post a Comment