Reputation: 11354
I start with Empty asp.net web api application with all default settings for VS 2017. I added one controller method with httpGet and result is fine.
Now I installed Microsoft.Owin.Host.SystemWeb
and added a OWIN Startup
class.
[assembly: OwinStartup(typeof(WebApp1.Startup))]
namespace WebApp1
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
After that I comment out global.asax
code as I believe I don't need it,
protected void Application_Start()
{
//GlobalConfiguration.Configure(WebApiConfig.Register);
}
Removing as well below code for Web API routes
//public static class WebApiConfig
//{
// public static void Register(HttpConfiguration config)
// {
// // Web API configuration and services
// // Web API routes
// config.MapHttpAttributeRoutes();
// config.Routes.MapHttpRoute(
// name: "DefaultApi",
// routeTemplate: "api/{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
// );
// }
//}
Now I'm getting 404 error while accessing the API, my OWIN startup code also calling. Whats wrong here? please suggest!.
Upvotes: 3
Views: 469
Reputation: 975
You have to add the following line of code at the end of your OWIN Configuration method:
app.UseWebApi(config);
Note: this method is located in:
using Owin; //Assembly System.Web.Http.Owin
Upvotes: 2