在它的文件名ASP.net MVC4的WebAPI路线 [英] ASP.net MVC4 WebApi route with file-name in it

查看:163
本文介绍了在它的文件名ASP.net MVC4的WebAPI路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到以下(或类似)的网址在我的ASP.net MVC4 /项目的WebAPI工作:

I'm trying to get the following (and similar) urls to work in my ASP.net MVC4/WebApi project:

http://127.0.0.1:81/api/nav/SpotiFire/SpotiFire.dll

负责此URL路径是这样的:

The route responsible for this url looks like this:

        config.Routes.MapHttpRoute(
            name: "Nav",
            routeTemplate: "api/nav/{project}/{assembly}/{namespace}/{type}/{member}",
            defaults: new { controller = "Nav", assembly = RouteParameter.Optional, @namespace = RouteParameter.Optional, type = RouteParameter.Optional, member = RouteParameter.Optional }
        );

如果我删除了它的工作原理就好了。在文件名,或者如果我加在URL后面一斜线,但也意味着我不能使用 Url.Route - 方法等等。我得到的错误是一个通用的404错误(下图)。

It works just fine if I remove the . in the file-name, or if I add a slash behind the URL, but that also means I can't use the Url.Route-methods etc. The error I get is a generic 404-error (image below).

我试着加入<的httpRuntime targetFramework =4.5axedUrlToFileSystemMapping =真/> 来我的web.config,而我也尝试添加

I've tried adding <httpRuntime targetFramework="4.5" relaxedUrlToFileSystemMapping="true" /> to my web.config, and I've also tried adding

<compilation debug="true" targetFramework="4.5">
  <buildProviders>
    <remove extension=".dll"/>
    <remove extension=".exe"/>
  </buildProviders>
</compilation>

和没有它似乎工作。所以我的问题基本上是,我怎么能得到这个URL工作,并正确映射?

And none of it seems to work. So my question is basically, how can I get this URL to work, and map correctly?

推荐答案

您可以在以下处理程序添加到&LT;处理&GT;你的<$ C $的C 部分>&LT; system.webServer&GT; :

You could add the following handler to the <handlers> section of your <system.webServer>:

<add 
    name="ManagedDllExtension" 
    path="api/nav/*/*.dll" 
    verb="GET" 
    type="System.Web.Handlers.TransferRequestHandler" 
    preCondition="integratedMode,runtimeVersionv4.0" 
/>

这将使得包含所有请求的.dll 通过托管管道送达。还要注意我如何他们仅限于GET动词来限制对性能的影响。

This will make all requests containing .dll be served through the managed pipeline. Also notice how I have limited them only to the GET verb to limit the performance impact.

这篇关于在它的文件名ASP.net MVC4的WebAPI路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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