繁体   English   中英

ASP.NET Web API属性路由

[英]asp.net web api attribute routing

API

[RoutePrefix("api/diagnostics")]
public class DiagnosticsController : ApiController
{
    [HttpPost]
    [Route("pings")]
    public IHttpActionResult Pings(Ping ping)
    {

    }
}

public class Ping
{
   public Guid ServerKey {get;set;}
   public DateTime CreatedDateTime {get;set;}
}

我正在尝试使用Postman应用程序测试该类。 这是截图

我收到的消息是:

{
"message": "No HTTP resource was found that matches the request URI 'http://localhost:61668/api/diagnostics/pings'.",
"messageDetail": "No action was found on the controller 'Diagnostics' that matches the request."
}

我无法理解为什么它与Diagnostics控制器中的发布操作不匹配 唯一配置的其他路由是默认路由:

 config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{key}",
                defaults: new { key = RouteParameter.Optional }
            );

还启用了属性路由:config.MapHttpAttributeRoutes();

尝试使用[FromBody]属性标记参数[FromBody] public IHttpActionResult Pings([FromBody] Ping ping)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM