简体   繁体   中英

ASP.NET MVC 2 Issue - Dot in Route

I'm blanking and need a quick hand. Google has failed me. I'm working on replacing WCF/REST Starter Kit with ASP.NET MVC. I want to make the transition as painless as possible so I'm trying to create a route to match the following URL:

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

I created the route in 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.

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:

<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:

Overriding a .svc Request With Routing

It turns out that for the *.svc extension, simply adding <httpRuntime relaxedUrlToFileSystemMapping="true" /> to the Web.config isn't enough.

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). Once you know that, it's easy enough to remove the build provider in your app's 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. By default this is set to 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. specifically pay attention to the part that starts with

This is done using a script named registermvc.wsf.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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