未找到条纹 Webhook 控制器

Stripe Webhook Controller Not Found

我有以下内容:

public class StripeController : Controller
{

    private readonly UserService _userService;

    public StripeController(UserService userService)
    {
        _userService = userService;
    }

    [HttpPost]

    public ActionResult StripeWebook()
    {
        return new HttpStatusCodeResult(HttpStatusCode.OK);
    }


    [HttpPost]
    [Route("api/stripewebhook")]
    public async Task<ActionResult> Index(CancellationToken ct)
    {
        var json = new StreamReader(Request.InputStream).ReadToEnd();

        var stripeEvent = StripeEventUtility.ParseEvent(json);

        switch (stripeEvent.Type)
        {
            case StripeEvents.ChargeRefunded:  // all of the types available are listed in StripeEvents
                var stripeCharge = Stripe.Mapper<StripeCharge>.MapFromJson(stripeEvent.Data.Object.ToString());
                break;
        }

        return new HttpStatusCodeResult(HttpStatusCode.OK);
    }


}

来自条带的请求产生错误:

The controller for path '/api/stripewebhook' was not found or does not implement IController

知道为什么当我从条带门户测试时会发生这种情况吗?

使用 WebApi 2 没问题。

下面是最小的 WebApi 控制器:

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Web;
    using System.Web.Http;

    namespace WebApplication1.Controllers
    {
        public class StripeController : ApiController
        {
            [HttpPost]
            [Route("api/stripewebhook")]
            public IHttpActionResult Index()
            {
                var json = new StreamReader(HttpContext.Current.Request.InputStream).ReadToEnd();
                return Ok();
            }
        }
    }

如果您从 VS 执行此操作,您可以从 http://localhost:(port)/api/stripewebhook

访问它

现在您只需要扩展它以包含条纹代码:

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Web;
    using System.Web.Http;

    namespace WebApplication1.Controllers
    {
        public class StripeController : ApiController
        {
            [HttpPost]
            [Route("api/stripewebhook")]
            public IHttpActionResult Index()
            {
                var json = new StreamReader(HttpContext.Current.Request.InputStream).ReadToEnd();

                var stripeEvent = StripeEventUtility.ParseEvent(json);

                switch (stripeEvent.Type)
                {
                    case StripeEvents.ChargeRefunded:  // all of the types available are listed in StripeEvents
                        var stripeCharge = Stripe.Mapper<StripeCharge>.MapFromJson(stripeEvent.Data.Object.ToString());
                        break;
                }

                return Ok();
            }
        }
    }