Can a new file extension be mapped to an existing handler in ASP.NET?
I have a scenario where my application will publish services that are consumed by both PC and mobile devices and I have an HTTPModule that I want to execute for mobile requests only. So I figured that the best way to do this is to point mobile requests to a different file extension and only allow the HTTPModule to process if the request is targeting that new extension.
I don't need a custom HTTPHandler for the new extension; I want to program the services as a normal .ASMX service, just with a different extension.
First, can I do this? If so, how do I do this so that requests to my new extension are handled the same way as .ASMX requests?
Second, is this the correct approach? Am I going to split and manage mobile or PC requests incorrectly?
Thanks, Dave
a source to share
Yes, it is possible to register a custom file extension and work with an existing .NET runtime. You can follow the steps below.
You need to add the ScriptMap to IIS (assuming IIS 7) and point it to the ASP.NET runtime so that IIS can route the request to the correct processor.
- In IIS7 go to your site or IIS root for server level registration.
- In the IIS group, go to the handler mappings
- In the Actions section, click Add Script Map
- Set access path to * .xxxx
- Set path to ASP.NET runtime (% windir% \ Microsoft.NET \ Framework64 \ v2.0.50727 \ aspnet_isapi.dll) or whatever version you are running.
You will then need to register a custom assembly provider for the file extension so that the .NET runtime can precompile your code, assuming you want it to work similarly to the * .asmx service.
Here is a list of some of 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>
Chances are you can copy one of the existing build providers based on the one that best suits 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>
a source to share