1
我有以下網址:網頁API路由
本地主機/ API /機/ somecode /所有
我有以下控制器:
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 }
);
}
}
但由於某種原因,它沒有解決 - 爲什麼顯而易見明顯的原因?
嗨 - 感謝您的 - 不幸的是,網址設定從傳統服務石頭:\ – iwayneo
嗨。夠公平的,但我的第一部分應該允許你的其他方法工作。已更新刪除提示。 –