C# MVC中DocuSign WebHook接收器类选择及控制器报错问题
Hey there, let's break down why you're hitting this error and walk through how to get your DocuSign WebHook up and running smoothly.
Why the Error Happens
The core issue here is a routing mismatch. In a standard MVC project, the default routing system looks for controllers that implement IController—which is what the regular Controller base class does. But ApiController belongs to ASP.NET Web API, which uses its own separate routing pipeline. When your WebHook request hits the MVC routing system, it doesn't recognize ApiController as a valid controller type, hence the frustrating error you're seeing.
Solutions to Try
1. Properly Configure Web API Routing
If you want to stick with ApiController, you need to ensure Web API's routing is set up correctly and runs before MVC routing:
First, create or update your
WebApiConfig.csfile (usually in theApp_Startfolder) with Web API route rules:public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Enable attribute routing for flexible endpoint setup (optional but recommended) config.MapHttpAttributeRoutes(); // Default Web API route template config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } }Then, in
Global.asax.cs, register Web API before MVC routes to make sure Web API handles its requests first:protected void Application_Start() { // Register Web API routing first GlobalConfiguration.Configure(WebApiConfig.Register); // Then register MVC routes and areas AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); }Double-check your WebHook URL: It should follow the Web API route pattern, e.g.,
https://yourdomain/api/DocuSign(since your controller is namedDocuSignController).
2. Use a Regular MVC Controller Instead
You don't need ApiController to handle WebHooks—they're just standard POST requests, which a regular MVC Controller can process perfectly. This avoids routing conflicts entirely:
public class DocuSignController : Controller { [HttpPost] public async Task<ActionResult> HandleWebHook() { // Read the WebHook payload from Request.InputStream or Request.Form // Process the DocuSign event data here // Return a 200 OK to confirm receipt of the WebHook return new HttpStatusCodeResult(HttpStatusCode.OK); } }
Your WebHook URL would then be https://yourdomain/DocuSign/HandleWebHook, which fits the standard MVC routing pattern.
3. Verify Web API Dependencies
If you're working with an older MVC project, make sure you have the necessary Web API NuGet packages installed. Run this command in the Package Manager Console:
Install-Package Microsoft.AspNet.WebApi
This ensures the ApiController type is properly recognized by the framework.
Quick Recap
Either align your routing to support Web API (and use the matching WebHook URL) or switch to a regular MVC controller—both approaches will fix the "controller not found" error. Since WebHooks are simple POST endpoints, the regular MVC controller route is often the simpler path if you don't need full Web API features.
内容的提问来源于stack exchange,提问作者Ragesh Puthiyedath Raju

