我似乎找不到一种方法来为通用的asp.net webhook设置这样的URI,路由以/portalapi/v1/*之类的东西开始。例如:
config.Routes.MapHttpRoute(
name: "PortalApi",
routeTemplate: "portalapi/v1/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
webhook接收器似乎只响应来自api/*:
形式的uri的帖子config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
我错过了什么吗?还是这是个bug?是否有人能够更改路由的开头并使其被webhook调用接受?
我通读了这篇微软文档,但没有找到任何答案:https://learn.microsoft.com/en-us/aspnet/webhooks/receiving/receivers
我在github上与AspNetWebHooks团队有一个开放的票。https://github.com/aspnet/AspNetWebHooks/issues/62
你不能,因为它不被支持,而且项目处于维护模式,所以它永远不会被支持。
查看源代码:
// Use a constant template since all WebHook constraints use the resulting route values and we have no
// requirements for user-specified route templates.
private static string ChooseTemplate()
{
var template = "/api/webhooks/incoming/"
+ $"{{{WebHookConstants.ReceiverKeyName}}}/"
+ $"{{{WebHookConstants.IdKeyName}?}}";
return template;
}