这是我的配置和代码。
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);
}
}
Global.asax.cs 中 Application_Start 的代码如下。
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);
}
为什么我访问 Url“http://localhost:8119/api/DeployLog”时收到 400 Http Response 消息。好像是代码
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
不起作用。我错过了什么吗?请帮我 。谢谢。