简体   繁体   English

ASP.NET MVC 2问题-路径中的点

[英]ASP.NET MVC 2 Issue - Dot in Route

I'm blanking and need a quick hand. 我要消隐,需要快速帮助。 Google has failed me. Google让我失败了。 I'm working on replacing WCF/REST Starter Kit with ASP.NET MVC. 我正在用ASP.NET MVC替换WCF / REST入门工具包。 I want to make the transition as painless as possible so I'm trying to create a route to match the following URL: 我想让转换尽可能轻松,所以我试图创建一个路由来匹配以下URL:

http://localhost/services/MyService.svc/UserInfo

I created the route in Global.asax.cs: 我在Global.asax.cs中创建了路由:

routes.MapRoute(
            "MyServiceDefault",
            "services/MyService.svc/{action}/{id}",
            new { 
                  controller = "MyService", 
                  action = "UserInfo", 
                  id = UrlParameter.Optional 
                }
        );

I soon realized that the request isn't even making it to my application because of the . 我很快意识到,由于,请求甚至没有发送到我的应用程序中. in the MyService.svc part of the URL. 在网址的MyService.svc部分中。

What am I missing to force the request to pass through to my application rather than being handled by the server as a static resource? 我缺少什么来迫使请求传递到我的应用程序,而不是由服务器作为静态资源处理?

Update 更新资料

I forgot to mention that I have also tried adding the following to Web.config to no avail: 我忘了提一下,我也曾尝试将以下内容添加到Web.config中无济于事:

<httpRuntime relaxedUrlToFileSystemMapping="true" />

It turns out that searching for the correct combination of terms will eventually yield results. 事实证明,搜索正确的术语组合最终会产生结果。 Phil Haack actually has a block post about this exact issue: 菲尔·哈克(Phil Haack)实际上有一篇有关此确切问题的大文章:

Overriding a .svc Request With Routing 用路由覆盖.svc请求

It turns out that for the *.svc extension, simply adding <httpRuntime relaxedUrlToFileSystemMapping="true" /> to the Web.config isn't enough. 事实证明,对于* .svc扩展名,仅向Web.config中添加<httpRuntime relaxedUrlToFileSystemMapping="true" />是不够的。

In one of the framework Web.config files, there is a build provider associated with the *.svc that takes over the request before it gets to .NET MVC (and fails since this isn't really a WCF service). 在一个框架Web.config文件中,有一个与* .svc关联的生成提供程序,该提供程序在请求到达.NET MVC之前接管了该请求(并且由于它不是真正的WCF服务而失败)。 Once you know that, it's easy enough to remove the build provider in your app's Web.config: 知道这一点之后,就很容易在应用程序的Web.config中删除构建提供程序:

<system.web>
  <compilation debug="true" targetFramework="4.0">
    <buildProviders>
      <remove extension=".svc"/>            
    </buildProviders>
    ...
</system.web>

Take a look at the RouteCollection.RouteExistingFiles property. 看一下RouteCollection.RouteExistingFiles属性。 By default this is set to false. 默认情况下,它设置为false。 It could be that your service is located under the Services path in your project and this is causing the issue. 可能是您的服务位于项目中“服务”路径下,这导致了问题。

This article tells how you can use different extensions with asp.net mvc application and still make them route to .NET framework. 本文告诉您如何在asp.net mvc应用程序中使用不同的扩展名,并仍然使它们路由到.NET框架。 specifically pay attention to the part that starts with 特别注意开头的部分

This is done using a script named registermvc.wsf.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM