views:

29

answers:

1

I have a scenario where my application is going to be publishing services that are consumed by both PC's and mobile devices, and I have a HTTPModule that I want to only perform work on only the mobile requests. So I thought the best way of doing this was to point the mobile requests to a different file extension and have the HTTPModule decide to process only if the request targets this new extension.

I don't need a custom HTTPHandler for the new extension; I want to program the services like a normal .ASMX service, just with a different extension.

First, can I do this? If so, how do I do it so that requests to my new extension are handled just like .ASMX requests?

Second, is this the right approach? Am I going about separating and managing the mobile vs. PC requests the wrong way?

Thanks, Dave

A: 

Yes, it is possible to register a custom file extension and have it work with the existing .NET runtime. You can perform the following steps.

You need to add a ScriptMap in IIS (assuming IIS 7) and point it to the ASP.NET runtime so that IIS can forward the request to the correct processor.

  1. In IIS7 go to your website, or IIS root to register at the server level
  2. Under the IIS group go to Handler Mappings
  3. Under Actions click Add Script Map
  4. Set Request Path to *.xxxx
  5. Set Path to the ASP.NET runtime (%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll) or whatever version you are running.

Then you will need to register a custom build provider for the file extension so that the .NET runtime can pre-compile your code assuming you wanted it to work similar to a *.asmx service.

Here are a list of some the built in build providers:

<system.web>
    <compilation>
        <buildProviders>
           <add extension=".aspx" type="System.Web.Compilation.PageBuildProvider" />
           <add extension=".ascx" type="System.Web.Compilation.UserControlBuildProvider" />
           <add extension=".master" type="System.Web.Compilation.MasterPageBuildProvider" />
           <add extension=".asix" type="System.Web.Compilation.ImageGeneratorBuildProvider" />
           <add extension=".asmx" type="System.Web.Compilation.WebServiceBuildProvider" />
           <add extension=".ashx" type="System.Web.Compilation.WebHandlerBuildProvider" />
           <add extension=".soap" type="System.Web.Compilation.WebServiceBuildProvider" />
           <add extension=".resx" type="System.Web.Compilation.ResXBuildProvider" />
           <add extension=".resources" type="System.Web.Compilation.ResourcesBuildProvider" />
           <add extension=".wsdl" type="System.Web.Compilation.WsdlBuildProvider" />
           <add extension=".xsd" type="System.Web.Compilation.XsdBuildProvider"/>
           <add extension=".js" type="System.Web.Compilation.ForceCopyBuildProvider" />
        </buildProviders>
    </compilation>
</system.web>

You can most likely just copy one of the existing build providers based on the one that best matches what you are doing and register it in your applications web.config

<system.web>
    <compilation>
        <buildProviders>
           <add extension=".xxxx" type="System.Web.Compilation.WebServiceBuildProvider" />
        </buildProviders>
    </compilation>
</system.web>
Wallace Breza