我試圖在瀏覽器中查看我的API控制器動作,我似乎無法找到此endpiont解析的URL。我想:我的簡單的API控制器動作似乎沒有工作
http://localhost:2797/api/Country/Testing
http://localhost:2797/api/Country/GetTesting
我得到這個錯誤:
<Error>
<Message>
The requested resource does not support http method 'GET'.
</Message>
</Error>
public class CountryController : ApiController
{
public HttpResponseMessage Testing()
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "value");
response.Content = new StringContent("hello", System.Text.Encoding.Unicode);
response.Headers.CacheControl = new CacheControlHeaderValue()
{
MaxAge = TimeSpan.FromMinutes(20)
};
return response;
}
}
請向我們展示您在'WebApiConfig.Register'中的路由配置。如果你沒有改變標準路由,你的控制器的正確URI就是'api/{controller}',沒有'{action}'部分。 –