可以将新的文件扩展名映射到 ASP.NET 中的现有处理程序吗?

发布于 2024-09-01 21:53:59 字数 319 浏览 3 评论 0原文

我有一个场景,我的应用程序将发布由 PC 和移动设备使用的服务,并且我有一个 HTTPModule,我只想对移动请求执行工作。因此,我认为最好的方法是将移动请求指向不同的文件扩展名,并让 HTTPModule 决定仅在请求针对此新扩展名时进行处理。

我不需要为新扩展自定义 HTTPHandler;我想像普通的 .ASMX 服务一样对服务进行编程,只是具有不同的扩展名。

首先,我可以这样做吗?如果是这样,我该如何做才能像处理 .ASMX 请求一样处理对新扩展名的请求?

其次,这是正确的做法吗?我是否会以错误的方式分离和管理移动与 PC 请求?

谢谢, 戴夫

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁吢 2024-09-08 21:53:59

是的,可以注册自定义文件扩展名并使其与现有的 .NET 运行时一起使用。您可以执行以下步骤。

您需要在 IIS 中添加一个 ScriptMap(假设是 IIS 7)并将其指向 ASP.NET 运行时,以便 IIS 可以将请求转发到正确的处理器。

  1. 在 IIS7 中,转到您的网站或 IIS 根目录以在服务器级别注册
  2. 在 IIS 组下,转到
  3. “操作”下的“处理程序映射”,单击“添加脚本映射”
  4. 将请求路径设置为 *.xxxx
  5. 将路径设置为 ASP.NET 运行时 (%windir%\ Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll) 或您正在运行的任何版本。

然后,您需要为文件扩展名注册一个自定义构建提供程序,以便 .NET 运行时可以预编译您的代码(假设您希望它像 *.asmx 服务一样工作)。

以下是一些内置构建提供程序的列表:

<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>

您很可能只需根据最适合您正在执行的操作的构建提供程序复制现有构建提供程序之一,并将其​​注册到您的应用程序 web.config 中

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文