我有一个MVC4应用程序 HttpHandler:

<system.web>
    ...
    <httpHandlers>
        <add path="Files" verb="*" type="MyHttpHandler" />
    </httpHandlers>
</system.web>

我也忽略了相关路径 RegisterRoutes 因此,MVC不处理“文件”的请求:

routes.IgnoreRoute("Files/{*pathInfo}");

问题是 MyHttpHandler 仅供“文件”请求,而不适用于其任何子女或子食者的请求。

我尝试使用 <location> 元素,但是将其工作起作用意味着您将在“路径”属性中硬编码应用程序的虚拟路径(例如, <location path='MyApp\Files'>).

什么是正确的方法来允许所有“文件”及其任何子文件夹(以及这些文件夹的子文件夹等)的所有请求。 MyHttpHandler?

有帮助吗?

解决方案

从头开始...<location> 似乎正常。不过,您都需要 <web><webServer> 条目以确保它适用于IIS和Visual Studio开发服务器。例如:

<location path="Files">`
    <system.webServer>
        <handlers>
            <add name="MyHandler" path="*" verb="*" type="MyHttpHandler" />
        </handlers>
    </system.webServer>
    <system.web>
        <httpHandlers>
            <add path="*" verb="*" type="MyHttpHandler" />
        </httpHandlers>
    </system.web>
</location>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top