【发布时间】:2017-10-08 20:08:10
【问题描述】:
我真的不明白为什么它不起作用。我有以下代码:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
[RoutePrefix("api/Profile")]
[System.Web.Http.AuthorizeAttribute]
[IdentityBasicAuthenticationAttribute]
public class ProfileApiController : ApiController
{
[HttpPost]
[ValidateApiContentLength]
[ValidateApiMimeMultipart]
[Route("Upload")]
public async Task<HttpResponseMessage> UploadDocumentAsync(string description)
{
//....
}
}
}
但是当我打电话时:http://localhost:11015/api/profile/Upload
我收到 404 错误:
{
"Message": "No HTTP resource was found that matches the request URI 'http://localhost:11015/api/profile/Upload'.",
"MessageDetail": "No action was found on the controller 'ProfileApi' that matches the request."
}
但洞察力说的是错误:
什么是不正确的?
【问题讨论】:
-
1.你是怎么打电话的? 2.你在项目中使用的是哪个模板:asp mvc还是asp mvc web api?
标签: asp.net-web-api asp.net-web-api2 asp.net-web-api-routing