WebApiConfig.Register清除由RouteConfig.RegisterRoutes APON部署定义的路由 [英] WebApiConfig.Register Clears routes defined by RouteConfig.RegisterRoutes apon deployment
问题描述
我在街头斗争在这里,当我尝试添加它似乎要摧毁所有我的MVC基地航线及地区航线API控制器。
I'm on struggle street here, When I try to add API controllers it seems to destroy all my MVC base routes and area routes.
在我的应用程序开始我称之为
On my application start I call
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
//FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
Util.RazorDebuggingSetup();
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
using System.Web.Mvc;
一个区域配置的例子:
An example of an area config:
namespace **.Areas.Console
{
public class ConsoleRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Console";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Console_default",
"Console/Index",
new { controller = "base", action = "Index"}
);
context.MapRoute(
"Console_default2",
"Console/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
}
}
我WebApiConfig类
My WebApiConfig Class
using System.Web.Http;
namespace **.Modules.MVC
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration configuration)
{
configuration.Routes.MapHttpRoute(
"API Default",
"api/{controller}/{id}",
new
{
id = RouteParameter.Optional
}
);
}
}
}
和路由类
using System.Web.Mvc;
using System.Web.Routing;
namespace **.Modules
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"ErrorHandler",
"Error/{action}/{id}",
new { controller = "Error", action = "Generic" , id = UrlParameter.Optional }
);
// Ignore old Friendly URLS.
// These should be removed.
routes.IgnoreRoute("Account/Login");
routes.IgnoreRoute("");
routes.IgnoreRoute("Website/{*pathInfo}");
routes.IgnoreRoute("Pages/{*pathInfo}");
routes.IgnoreRoute("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
routes.IgnoreRoute("{*allasp}", new { allasp = @".*\.asp(/.*)?" });
routes.IgnoreRoute("{*allhtml}", new { allhtml = @".*\.html(/.*)?" });
routes.IgnoreRoute("{*allphp}", new { allphp = @".*\.php(/.*)?" });
//Default Mvc ignore.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
//routes.MapRoute(
// "404-PageNotFound",
// "{*url}",
// new { controller = "Error", action = "HttpError" }
//);
}
}
}
现在在我的本地IIS的一切功能,如预期,但是当我尝试我的生产服务器上访问URL,我得到以下404。
Now on my local iis everything functions as expected but when I try access urls on my production server i get the following 404.
当我打开我的路线调试我看到这个地方。
When I turn on my route debugging i see this on local.
- 匹配当前请求:假
- 地址:r.ashx / {模块} / {*}路径
- 默认值:(空)
- 限制:(空)
- DataTokens:(空)
- 匹配当前请求:真
- 地址:控制/索引
- 默认值:控制器=基地,行动=索引
- 限制:(空)
- DataTokens:命名空间= BookEasy.Areas.Control *,面积=控制,UseNamespaceFallback =假
- 匹配当前请求:真
- 地址:控制/ {控制器} / {行动} / {ID}
- 默认值:行动=指数,ID = UrlParameter.Optional
- 限制:(空)
- DataTokens:命名空间= BookEasy.Areas.Control *,面积=控制,UseNamespaceFallback =假
- 匹配当前请求:假
- 地址:控制台/索引
- 默认值:控制器=基地,行动=索引
- 限制:(空)
- DataTokens:命名空间= BookEasy.Areas.Console *,面积=控制台,UseNamespaceFallback =假
- 匹配当前请求:假
- 地址:控制台/ {控制器} / {行动} / {ID}
- 默认值:行动=指数,ID = UrlParameter.Optional
- 限制:(空)
- DataTokens:命名空间= BookEasy.Areas.Console *,面积=控制台,UseNamespaceFallback =假
- 匹配当前请求:假
- 地址:API / {控制器} / {ID}
- 默认值:ID =
- 限制:(空)
- DataTokens:(空)
- 匹配当前请求:假
- 网址:error / {行动} / {ID}
- 默认值:控制器=错误,行动=通用,ID = UrlParameter.Optional
- 限制:(空)
- DataTokens:(空)
- 匹配当前请求:假
- 地址:帐户/登录
- 默认值:(空)
- 限制:(空)
- DataTokens:(空)
- 匹配当前请求:假
- 网址:
- 默认值:(空)
- 限制:(空)
- DataTokens:(空)
- 匹配当前请求:假
- 网址:网址/ {*} PATHINFO
- 默认值:(空)
- 限制:(空)
- DataTokens:(空)
- 匹配当前请求:假
- 地址:页/ {*} PATHINFO
- 默认值:(空)
- 限制:(空)
- DataTokens:(空)
- 匹配当前请求:假
- 网址:{ allaspx}
- 默认值:(空)
- 约束:allaspx = 的的.aspx(/.*)?
- DataTokens:(空)
- Matches Current Request: False
- Url: {allaspx}
- Defaults: (null)
- Constraints: allaspx = ..aspx(/.*)?
- DataTokens: (null)
- 匹配当前请求:假
- 网址:{ allasp}
- 默认值:(空)
- 约束:allasp = 的.asp的(/.*)?
- DataTokens:(空)
- Matches Current Request: False
- Url: {allasp}
- Defaults: (null)
- Constraints: allasp = ..asp(/.*)?
- DataTokens: (null)
- 匹配当前请求:假
- 网址:{ allhtml}
- 默认值:(空)
- 约束:allhtml = 的的.html(/.*)?
- DataTokens:(空)
- Matches Current Request: False
- Url: {allhtml}
- Defaults: (null)
- Constraints: allhtml = ..html(/.*)?
- DataTokens: (null)
- 匹配当前请求:假
- 网址:{ allphp}
- 默认值:(空)
- 约束:allphp = 的.PHP(/.*)?
- DataTokens:(空)
- Matches Current Request: False
- Url: {allphp}
- Defaults: (null)
- Constraints: allphp = ..php(/.*)?
- DataTokens: (null)
- 匹配当前请求:假
- 网址:{}资源个.axd / {*} PATHINFO
- 默认值:(空)
- 限制:(空)
- DataTokens:(空)
- 匹配当前请求:假
- 网址:{图标}
- 默认值:(空)
- 约束:图标=的favicon.ico(/.*)(的/。)?
- DataTokens:(空)
- Matches Current Request: False
- Url: {favicon}
- Defaults: (null)
- Constraints: favicon = (./)?favicon.ico(/.*)?
- DataTokens: (null)
- 匹配当前请求:真
- 网址:{*}包罗万象
- 默认值:(空)
- 限制:(空)
- DataTokens:(空)
对不起文本的该壁似乎是显示数据没有表的最佳方式。 <一href=\"http://meta.stackexchange.com/questions/73566/is-there-any-markdown-to-create-tables\">http://meta.stackexchange.com/questions/73566/is-there-any-markdown-to-create-tables
Sorry for that wall of text seemed to be the best way to show the data without a table. http://meta.stackexchange.com/questions/73566/is-there-any-markdown-to-create-tables
反正与问题。
而现在我所看到的,当我调试我部署的服务器上的路由信息。
And now what I see when I debug routes on my deployed server.
- 匹配当前请求:假
- 地址:r.ashx / {模块} / {*}路径
- 默认值:(空)
- 限制:(空)
- DataTokens:(空)
- 匹配当前请求:真
- 网址:{*}包罗万象
- 默认值:(空)
- 限制:(空)
- DataTokens:(空)
其他的一些事实。
版本的mvc = 4
Mvc Version = 4
IIS = 7
当我删除WebApiConfig.Register(GlobalConfiguration.Configuration);表相符(但都错过了API / *路线)。
When I remove WebApiConfig.Register(GlobalConfiguration.Configuration); the tables match (but both miss the api/* route).
所以,这个问题的核心。为什么这两个路由表不同,当我加入WebApiConfig.Register?
So to the core of the question. Why are these two route tables different when I add WebApiConfig.Register?
----------------编辑1 ------------------
---------------- EDIT 1 ------------------
另一个音符加WebApiConfig.Register也打破了我的捆绑路线:(
As another note the addition of WebApiConfig.Register also breaks my bundling routes :(.
推荐答案
做一些挖掘我注意到这一点。
<一href=\"http://stackoverflow.com/a/26972184/2560687\">http://stackoverflow.com/a/26972184/2560687
Doing some digging I noticed this. http://stackoverflow.com/a/26972184/2560687
IMO指向一个是坏它的非特异性。
IMO point one is bad as its non specific.
请注意2点:
我的本地机器曾在GAC这些DLL,但部署的机器没有。并复制本地=真正的DLL和一切工作:D
Note Point 2: My local machine had these dlls in the gac but deployment machine did not. And copy local = true to the dlls and everything is working :D
这里有什么正确的程序问题回答时,其建议的回答不同的问题?
What is the correct procedure here for question answering when its a proposed answer to a different question?
这篇关于WebApiConfig.Register清除由RouteConfig.RegisterRoutes APON部署定义的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!