C# Web API中没有显示操作方法,为什么?

C# Web API中没有显示操作方法,为什么?,c#,asp.net-web-api,C#,Asp.net Web Api,我有网络API,我有书面的行动方法。但当我运行应用程序时,它并不正确可见。我无法在所附图像中看到SendPushNotification 控制器代码: [RoutePrefix("api/OTP")] public class OTPController : ApiController { public IHttpActionResult Get(int id) { return Ok("value"); } [HttpGet] publ

我有网络API,我有书面的行动方法。但当我运行应用程序时,它并不正确可见。我无法在所附图像中看到SendPushNotification

控制器代码:

[RoutePrefix("api/OTP")]
public class OTPController : ApiController
{
    public IHttpActionResult Get(int id)
    {
        return Ok("value");
    }
    [HttpGet]
    public IHttpActionResult SendPushNotification(string userId, string factorId, string domain)
    {
        var response = _oTPRepository.SendPushNotification(userId, factorId, domain);

        return Ok(response);
    }

在您的方法上添加路由,如下所示:

[HttpGet]
[Route("SendPushNotification")]
    public IHttpActionResult SendPushNotification(string userId, string factorId, string domain)
    {
        var response = _oTPRepository.SendPushNotification(userId, factorId, domain);

        return Ok(response);
    }
这将与控制器中的RoutePrefix相结合,并提供您想要的。
您也可以根据需要调用它,也可以根据您的API调用任何有意义的方法。

在前面提到的图像中,第二种方法就是您实际需要的方法。 操作方法的默认路由是api/{controller\u name}。 如果要以给定名称访问该方法,则必须在该操作方法上方设置路由属性。
像[路由(“api/OTP/SendPushNotification”)]

如何配置路由?您是否正在使用
MapHttpAttribute路由()
?您不会看到方法,只会看到资源。您的操作是第二个
GET
列表。请使方法有意义(如帖子)并提供说明。不能有多个参数冲突的操作。路由器将无法确定要调用什么。请执行
[HttpGet,ActionName(“SendPushNotification”)]
。如果您有其他现成的操作,请显示您的路线映射。撇开这一点不谈:从语义上讲,让数据发送到的动作听动词GET是没有意义的。这应该是一个事后行动。