我有以下网址:
本地主机/api/机器/somecode/all
我有以下控制器:
public class MachineController : ApiController
{
public IEnumerable<Machine> Get()
{
return new List<Machine>
{
new Machine
{
LastPlayed = DateTime.UtcNow,
MachineAlertCount = 1,
MachineId = "122",
MachineName = "test",
MachinePosition = "12",
MachineStatus = "test"
}
};
}
public IEnumerable<Machine> All(string code)
{
return new List<Machine>
{
new Machine
{
LastPlayed = DateTime.UtcNow,
MachineAlertCount = 1,
MachineId = "122",
MachineName = "test",
MachinePosition = "12",
MachineStatus = "test"
}
};
}
}
以及以下路线:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "MachineApi",
routeTemplate: "api/machine/{code}/all"
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
但由于某种原因,它没有解决 - 有什么明显的原因吗?