I have added a Api Controller in my asp.net mvc5 web project, along with other controllers...i am contstantly getting resource not found error. please point out mistakes i might be making...
following is my Register method for WebApi routes
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
here is the Global.asax.cs
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
//GlobalConfiguration.Configure(WebApiConfig.Register);
WebApiConfig.Register(GlobalConfiguration.Configuration);
}
here is my Api controller class
public class SearchController : ApiController
{
public IEnumerable<string> GetSearch()
{
return new string[] { "value1", "value2" };
}
}
"http://sukhdev.com/api/search" is the url scheme i use to call web api, but it persistenly "The resource cannot be found."