MVC 应用程序中 ASP.NET WCF 和 Routes.Add 的 ActionLink 行为
我想在我的 C#.Net 项目中托管 WCF 4 和 MVC 3。但是当我添加 WCF 的服务路径时,Html.ActionLink 开始为 MVC 应用程序创建错误的 url。我的路由表创建为:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
RouteTable.Routes.Add(new ServiceRoute("api1/projects", new WebServiceHostFactory(), typeof(Projects)));
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
上面的路由表创建了 WCF 和 MVC 应用程序的正确访问路径,但是 Html.ActionLink
创建了编辑链接,而
http://localhost:8000/api1/projects?action=Edit&controller=technology&id=2
不是
http://localhost:8000/technology/Edit/2
如果我省略了以 RouteTable.Routes.Add
,ActionLink
按预期工作(当然不是 WCF)。如何添加 WCF 路由并确保 actionlink 行为不会更改?
I'm want to host both WCF 4 and MVC 3 in my C#.Net project. But when I add the service paths for WCF, Html.ActionLink starts creating a wrong url for MVC app. My route table is created as:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
RouteTable.Routes.Add(new ServiceRoute("api1/projects", new WebServiceHostFactory(), typeof(Projects)));
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Above route table creates the right access paths to both the WCF and MVC applications, but Html.ActionLink
creates the edit links as
http://localhost:8000/api1/projects?action=Edit&controller=technology&id=2
instead of
http://localhost:8000/technology/Edit/2
If I omit the line starting with RouteTable.Routes.Add
, the ActionLink
works as expected (and of course not the WCF). How can I add the WCF routes and make sure actionlink behaviour doesn't change?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将
ServiceRoute
注册放在MapRoute
之后。Try putting
ServiceRoute
registration afterMapRoute
.