Hi I am just starting to mess with WebApi to setup a REST api for my angular app.
I simply just added a "Web API 2 Controller with read/write actions"
I then just try to test it by just typing the url in the browser but I get a 404.
Everything is pretty much out of the box.
WebApiConfig.cs looks like
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
RouteConfig.cs is
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Global.asax
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
GlobalConfiguration.Configure(WebApiConfig.Register);
InitializeDatabase("Data Source=.;Initial Catalog=msproto;Integrated Security=True;MultipleActiveResultSets=True;");
}
Is there something I have to add to the web config? If I add a normal controller "MVC 5 Controller with read/write actions" it will hit my breakpoints in the get requests.