ASP.NET MVC - 路由 - 文件扩展动作 [英] ASP.NET MVC - Routing - an action with file extension

查看:174
本文介绍了ASP.NET MVC - 路由 - 文件扩展动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法来实现调用网址 HTTP://mywebsite/myarea/mycontroller/myaction.xml
这基本上是假的请求文件,但结果将是一个动作的操作,将成为动态创建一个文件?

is there a way to achieve calling URL http://mywebsite/myarea/mycontroller/myaction.xml This would basically "fake" requesting a file but the result would be an action operation that would serve a file created dynamically?

我试过这样:

context.MapRoute(
                "Xml_filename",
                "Xml/{controller}/{action}.xml"
            );

但每当有在URL路由失败,表现为我是直接请求文件fil​​extension。

but whenever there is a filextension in the URL the routing fails and behaves as I was requesting a file directly.

我怀疑这可能是因为在使用延长少URL处理程序。

I suspect this might be because of using extension less url handler.

<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
        <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
        <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

感谢您的任何建议。

的Jakub

推荐答案

您需要在web.config中的XML文件的请求映射到 TransferRequestHandler 。否则,IIS将处理请求。

You need to map requests for your XML files to TransferRequestHandler in web.config. Otherwise IIS will handle the request.

乔恩·加洛韦解释如何做到这一点<一个href=\"http://weblogs.asp.net/jongalloway/asp-net-mvc-routing-intercepting-file-requests-like-index-html-and-what-it-teaches-about-how-routing-works\"相对=nofollow>这里。

Jon Galloway explains how to do this here.

总之,你在你的web.config添加此元素的位置/ system.webServer /处理器:

In summary, you add this element to location/system.webServer/handlers in your web.config:

<add name="XmlFileHandler" path="*.xml" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

这篇关于ASP.NET MVC - 路由 - 文件扩展动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆