Using non asp.net file extensions with asp.net

As a developer it's pretty interesting the type of things you run into. Well, couple weeks ago at work, I ran into a situation where I had to reverse engineer the webservice from php, however, still had to maintain the .php extension on the endpoint. In asp.net this is pretty easy to handle using handlers and build providers. Here's how you can configure your asp.net so that it builds your .php file as if it were .asmx/.aspx.

  1. First of all, you'll need to configure your IIS to handle requests to .php (.cfm/.jsp etc…) with aspnet_isapi. Browse to your virtual directory ->properties->Configuration->Add extension mapping. Configure it as show in the picture.


  2. In your web.config file add a httpHandlers section. I'll be treating .php as a webservice, thus a webservicehandlerfactory.

    <httpHandlers>

    <add path="*.php" verb="*" type="System.Web.Services.Protocols.WebServiceHandlerFactory, System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>

    </httpHandlers>

  3. You'll also need to associate a build provider. The idea here is little different than just using a custom HttpHandler, what we are trying to do is run .php file as an entity as if it were a .asmx file with code behind. For example let's say I replaced all my .aspx file with .php extension, without changing anything else. If you look into your web.config in asp.net Folder, you'll find all the build providers associated with different extensions. ASP.Net uses these to build the incoming requests from a given file. Add the following inside your web.config in system.web

    <
    compilation>

<buildProviders>

<add extension=".php" type="System.Web.Compilation.WebServiceBuildProvider"/>

<!—you could treat it as aspx page if you want to as well
<add extension=".php" type="System.Web.Compilation.PageBuildProvider"/>-->

</buildProviders>

</compilation>

Print | posted on Monday, October 15, 2007 11:29 PM

Feedback

# re: Using non asp.net file extensions with asp.net

Left by ron at 7/30/2008 11:51 AM
Gravatar Thanks. This was exactly what I needed.

Your comment:





 
Please add 8 and 5 and type the answer here:

Copyright © Bigyan Rajbhandari