I have an WebAPI 2 app with OWIN. Now I'm trying to add an MVC 5 controller to everything, but my MVC routes are not being found. I'm receiving the following error:
No HTTP resource was found that matches the request URI 'https://localhost:44320/home'.
No type was found that matches the controller named 'home'.
The controller's name is correct (HomeController
), it is public, and I'm configuring the routes in 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);
}
I also have the 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);
}
}
I've noticed that when I comment out the app.UseWebApi(config)
line, the MVC routes start to work again.
Does anyone know what is going on and how to solve this?
Thanks
The app.UseWebApi()
command is for self-hosting with OWIN, which is incompatible with MVC, so you can only use it when your project is exclusively a Web Api project. Just remove that, and you're golden.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With