我是 WEB API 的新手,并尝试遵循站点上设置的路由方法
在我的控制器中,我有所有基于标准动词的动作 Get ... Delete。
我还有其他一些基于 Get Verb 的操作。我们为每个控制器注册路由,下面是我的路由设置。见下文。我的 Actions 方法具有如下属性。但是,当我输入例如时,http://server:49279/api/Licenses
我收到错误消息 MultipleActions match request The Actions Search,SearchByArtistId
当控制器被硬编码时,不确定如何处理
任何帮助都会很有价值,因为我无法在线找到解决方案
谢谢
[System.Web.Http.AcceptVerbs(new string[] { "Get" })]
[System.Web.Http.ActionName("PublishersByLicense")]
public HttpResponseMessage PublishersByLicense(Guid Id)
{
string vControllerName="Licenses";
config.Routes.MapHttpRoute
(
name: "PublishersByLicense" + vControllerName,
routeTemplate: "api/" + vControllerName + "/" + "PublishersByLicense" + "/{aLicenseId}",
defaults: new
{
controller = vControllerName,
action = "PublishersByLicense"
},
constraints: new
{
httpMethod = new HttpMethodConstraint(HttpMethod.Get)
}
);
config.Routes.MapHttpRoute
(
name: "Search" + vControllerName,
routeTemplate: "api/" + vControllerName + "/" + "Search" + "/{aTrackIds}",
defaults: new
{
controller = vControllerName,
action = "Search"
},
constraints: new
{
httpMethod = new HttpMethodConstraint(HttpMethod.Get)
}
);
config.Routes.MapHttpRoute
(
name: "GetAll" + vControllerName,
routeTemplate: "api/" + vControllerName,
defaults: new
{
controller = vControllerName
},
constraints: new
{
httpMethod = new HttpMethodConstraint(HttpMethod.Get)
}
);
config.Routes.MapHttpRoute
(
name: "GetSingle" + vControllerName,
routeTemplate: "api/" + vControllerName + "/{aLicenseId}",
defaults: new
{
controller = vControllerName
},
constraints: new
{
httpMethod = new HttpMethodConstraint(HttpMethod.Get)
}
);
这是我的控制器代码
[System.Web.Http.AcceptVerbs(new string[] { "Get" })]
[System.Web.Http.ActionName("Search")]
public HttpResponseMessage Search([FromUri]Guid[] aTrackIds)
{
public HttpResponseMessage Get()
{