[英]Action method not showing in Web API, why?
我有 Web API,我寫了 action 方法。 但是當我運行應用程序時它不正確可見。 我在附加圖像中看不到 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);
}
在您的方法上添加一個 Route,如下所示:
[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_name}。 如果您想以您的給定名稱訪問該方法,則您已在該操作方法上方設置了路由屬性。 像 [Routing("api/OTP/SendPushNotification")]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.