Here is my configuration and code .
public class DeployLogController : ApiController
{
// GET /api/DeployLog
public List<DeployLogModel> Get(Guid deployDetailId, Guid? deployLogId)
{
DeployLogService service = DeployLogService.Instance;
return service.GetNewestDeployLogs(deployDetailId, deployLogId).ToList();
}
// POST /api/DeployLog
public void Post(DeployLogModel deployLogModel)
{
DeployLogService service = DeployLogService.Instance;
service.SavaDeployLogByServer(deployLogModel);
}
}
and the code of Application_Start in Global.asax.cs is below.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Login", action = "Login", id = UrlParameter.Optional }
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
BundleTable.Bundles.RegisterTemplateBundles();
Configure(GlobalConfiguration.Configuration);
}
Why did I got 400 Http Response message When I accessed the Url “http://localhost:8119/api/DeployLog”. Seems the code
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
doesn’t work.Did I miss something ? please help me . Thanks.
Use Phil Haack’s Routing Debugger to determine if the correct route is being hit.
It looks like you’re either hitting the wrong route, or your route does not have a controller method that corresponds with it (at first glance, it appears that your setup is expecting a controller method called GET, not DeployLog.