我有一个带有 OWIN 的 WebAPI 2 应用程序。现在我正在尝试向所有内容添加一个 MVC 5 Controller ,但没有找到我的 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'.
Controller 的名称是正确的(
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 Startup 类(class):
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 路由又开始工作了。有谁知道发生了什么以及如何解决这个问题?
谢谢
最佳答案
app.UseWebApi()
命令用于OWIN自托管,与MVC不兼容,所以只有在你的项目是专门的Web Api项目时才能使用。只需删除它,你就是金色的。
关于asp.net-mvc - WebAPI + MVC + Owin : MVC routes don't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43850125/