ASP.NET MVC 2期 - 圆点路线 [英] ASP.NET MVC 2 Issue - Dot in Route
问题描述
我消隐,需要一个快速的手。谷歌已经没有了我。我正在与ASP.NET MVC替换WCF / REST入门套件。我想使过渡尽可能无痛,所以我试图创建匹配以下网址路线:
HTTP://localhost/services/MyService.svc/UserInfo
我创建的Global.asax.cs路线:
routes.MapRoute(
MyServiceDefault
服务/ MyService.svc / {}动作/(编号),
新{
控制器=为MyService
行动=的UserInfo
ID = UrlParameter.Optional
}
);
我很快意识到,请求甚至没有做它我的,因为。
在 MyService.svc $ C的应用$ C> URL的一部分。
我缺少强制要求通过我的应用程序,而不是由服务器正在处理一个静态资源?
更新
我忘了提,我也尝试添加以下到Web.config中不得要领:
<的httpRuntime relaxedUrlToFileSystemMapping =真/>
事实证明,搜索方面将最终产生结果的正确组合。菲尔哈克实际上有一个块后这个确切的问题:
<一个href=\"http://haacked.com/archive/2010/09/07/routing-and-build-providers.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3a%20haacked%20%28you%27ve%20been%20HAACKED%29\">Overriding一.SVC请求与路由
原来,为* .svc扩展,只需添加&LT;的httpRuntime relaxedUrlToFileSystemMapping =真/&GT;
到Web.config是不够的。
在框架的Web.config文件之一,存在与* .SVC接管请求它获取到.NET MVC之前(和失败,因为这是不是一个真正的WCF服务)相关的生成提供。一旦你知道,它很容易去除生成提供在应用程序的Web.config文件:
&LT;&的System.Web GT;
&LT;编译调试=真targetFramework =4.0&GT;
&LT; buildProviders&GT;
&LT;删除扩展= /&GTSVC。
&LT; / buildProviders&GT;
...
&LT; /system.web>
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>
这篇关于ASP.NET MVC 2期 - 圆点路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!