我有 2 controllers,我收到错误:
> AmbiguousActionException: Multiple actions matched. The following
> actions matched route data and had all constraints satisfied:
> WebApi.Controllers.BlacklistController.GetBlacklists (WebApi)
> WebApi.Controllers.WhitelistController.GetWhitelists (WebApi)
这是我的控制器
[Produces("application/json")]
[Route("api/infrastructure/blacklist")]
public sealed class BlacklistController : Controller
{
private readonly IInfrastructure _infrastructure;
public BlacklistController(IInfrastructure infrastucture) => _infrastructure = infrastucture;
[HttpGet]
[Route("/")]
public async Task<IEnumerable<BlacklistedAgent>> GetBlacklists() => await _infrastructure.GetBlacklistedAgents().ConfigureAwait(false);
}
WhitelistController.cs:
[Produces("application/json")]
[Route("api/infrastructure/whitelist")]
public sealed class WhitelistController : Controller
{
private readonly IInfrastructure _infrastructure;
public WhitelistController(IInfrastructure infrastructure) => _infrastructure = infrastructure;
[HttpGet]
[Route("/")]
public async Task<IEnumerable<WhitelistRequest>> GetWhitelists() => await _infrastructure.GetPendingWhitelistRequests().ConfigureAwait(false);
[HttpPost]
[Route("/")]
public async Task<ActionResult<WhiteListingResponse>> RequestWhitelisting(Guid agentId, string fqdn)
{
var result = await _infrastructure.RequestWhitelistingForAgent(agentId, fqdn).ConfigureAwait(false);
switch (result)
{
case WhiteListingResponse.Blacklisted:
return Forbid();
case WhiteListingResponse.SuccessfullyAddedToAwaitingWhitelist:
return Ok();
case WhiteListingResponse.ConflictStopsAddingToAwaitingWhitelist:
{
await _infrastructure.CreateUnresolvedIdentity(agentId, fqdn).ConfigureAwait(false);
return Conflict();
}
default:
return BadRequest();
}
}
}
为什么不是disambiguating基于Route attribute控制器上的方法?