我有一个OWIN的WebAPI 2应用程序。现在我试图添加一个MVC 5控制器到一切,但我的MVC路线没有被发现。我收到以下错误:WebAPI + MVC + Owin:MVC路线不起作用
No HTTP resource was found that matches the request URI ' https://localhost:44320/home '.
No type was found that matches the controller named 'home'.
控制器的名称是正确的(HomeController
),它是公开的,我配置在Global.asax中路线:
protected void Application_Start()
{
HttpConfiguration config = GlobalConfiguration.Configuration;
ModelBinderConfig.RegisterModelBinders(config.Services);
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
我也有在OWIN启动类:
public class Startup
{
public void Configuration(IAppBuilder app)
{
var config = GlobalConfiguration.Configuration;
var globalExceptionHandler = GetGlobalExceptionHandlerConfiguration();
config.Services.Replace(typeof(IExceptionHandler), globalExceptionHandler);
app.UseWebApi(config);
}
}
我注意到,当我注释掉app.UseWebApi(config)
线,MVC的路线开始重新工作。
有谁知道发生了什么事以及如何解决这个问题?
谢谢
我相信你需要你的MVC路线后,注册你的WebAPI路线。这可以通过在'Application_Start'中完成,通过移动'GlobalConfiguration.Configure(WebApiConfig.Register);'在RouteConfig.RegisterRoutes(RouteTable.Routes)下面'' – peinearydevelopment
@peinearydevelopment:我试过了,仍然得到相同的错误 – peflorencio