Custom File Extensions in ASP.NET 2.0

Custom File Extensions in ASP.NET 2.0

  • Comments 1

Got a question a while back from a customer asking how to enable ASP.NET 2.0 pages with custom file extensions, so I played around a bit to see how to do it, and here's what I came up with:

1. Open up the IIS 5.1 or 6 management console, and navigate to the virtual directory (or web site) that you want to configure. Right-click the folder and select Properties.

2. On the Directory (or Web Site) tab, click the Configuration button.

3. On the Mappings tab, click Add, and enter aspnet_isapi.dll (the path is under Windows\Microsoft.net\Framework\<version>\...check the existing mapping for .aspx if you need the exact path) as the Executable, and your desired extension under Extension (I used .foo). Clear the "Check that file exists" box. Click OK (if OK is greyed out, tab around in the textboxes a bit, that usually seems to clear the issue that prevents it from being active). Click OK.

4. In your web.config file (or the main web.config for the machine, if you want this to apply to all sites), add the following HttpHandler mapping (inside the <system.web> tags:

<httpHandlers>

      <add path="*.foo" verb="*" type="System.Web.UI.PageHandlerFactory" validate="true" />

</httpHandlers>

5. Also in your web.config, add the following Build Provider mapping (goes between the <compilation> tags, you may need to edit the default tag, since in ASP.NET 2.0 it defaults to a self-closing tag):     

<buildProviders>

         <add extension=".foo" type="System.Web.Compilation.PageBuildProvider" />

</buildProviders>

The complete <compilation tag should look similar to the following:

<compilation debug="false" strict="false" explicit="true">

         <buildProviders>

                  <add extension=".foo" type="System.Web.Compilation.PageBuildProvider" />

         </buildProviders>

</compilation>

6. Add a new web form to the page (probably easiest to stick with single file pages for this), add controls, etc., and when you're finished with the page, rename the extension to the one you configured in IIS.

7. Browse with IIS to test.

  • Great Article! worked straight away.

    Thanks

Page 1 of 1 (1 items)