可以将新的文件扩展名映射到 ASP.NET 中的现有处理程序吗?
我有一个场景,我的应用程序将发布由 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,可以注册自定义文件扩展名并使其与现有的 .NET 运行时一起使用。您可以执行以下步骤。
您需要在 IIS 中添加一个 ScriptMap(假设是 IIS 7)并将其指向 ASP.NET 运行时,以便 IIS 可以将请求转发到正确的处理器。
然后,您需要为文件扩展名注册一个自定义构建提供程序,以便 .NET 运行时可以预编译您的代码(假设您希望它像 *.asmx 服务一样工作)。
以下是一些内置构建提供程序的列表:
您很可能只需根据最适合您正在执行的操作的构建提供程序复制现有构建提供程序之一,并将其注册到您的应用程序 web.config 中
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.
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:
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