我一直在建立一個WebAPI,試圖路由到正確的方法與ActionName。它適用於我嘗試調用的其中一個方法,但另一個方法會得到404錯誤。WebAPI ActionName路由半工作
我的WebAPI配置文件:
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
我的WebAPI控制器的方法被格式化爲這樣:
這第一個是工作之一:
[ActionName("postdb")]
public IEnumerable<string[]> postDB(string id)
{ ...
這第二個沒有:
[ActionName("getquery")]
public IEnumerable<string[]> getQuery(string tables)
{ ...
我他們都呼籲從角以同樣的方式(溫度是被作爲參數傳遞的字符串):
$http.post('api/Test/postdb/' + temp).then(function (response) { ...
和
$http.get('api/Test/getquery/' + temp).then(function (response) { ...
我已經試過兩個行爲的改變名稱,第一個不管名字都起作用,第二個不管名字都不起作用。我也嘗試重新排序它們,在GET和POST之間切換,並更改參數。
有什麼建議嗎?
謝謝你的建議。我會努力改變它! – user6846524