Error: Multiple controller types Were found that match the URL

Asked

Viewed 299 times

2

When requesting a service by my App, gives me this error:

Multiple controller types Were found that match the URL. This can if happen attribute Routes on Multiple controllers match the requested URL. r n r nThe request has found the following matching controller types:
\r\nAutorizadorService.Controllers.NegarController\r\nAutorizadorService.Controllers.AtualizaController",

But by the App I have it:

public async Task UpdateLiberacaoAsync(double id, string value, List<Liberacao> liber)
        {
            try
            {
                string url = $"http://www.inetglobal.com.br/autorizador/api/atualiza/{id}/{value}";
                var uri = new Uri(string.Format(url));
                var data = JsonConvert.SerializeObject(liber);
                var content = new StringContent(data, Encoding.UTF8, "application/json");
                HttpResponseMessage response = null;
                response = await client.PutAsync(uri, content);

                //if (!response.IsSuccessStatusCode)
                //{
                //    throw new Exception("Erro ao atualizar tabela de liberacao");
                //}
            }
            catch (Exception ex)
            {
                string er = ex.Message;
            }
        }

and in my service (Atorizadorservice) see this: Controller

[EnableCors(origins: "*", headers: "*", methods: "*")]
    [RoutePrefix("api/Atualiza")]
    public class AtualizaController : ApiController
    {
        AutorizadorContext contexto = new AutorizadorContext();
        PedidoLiberacao liberacao = new PedidoLiberacao();

        [Route("{id}/{value}")]
        [AcceptVerbs("Put")]
        public void PutItensLiberacao(int id, string value)
        {
            liberacao.AtualizaLiberacao(id, value);
        }
    }

and my model service

[Route("{id}/{value}")]
        public void AtualizaLiberacao(int id, string value)
        {
            var lista = contexto.Liberacoes
                        .Where(l => l.IdOrcamento == id)
                        .ToList();

            lista.ForEach(f =>
            {
                f.FlagLiberacao = 1;
                f.AutorizouReceberAtrazado = value;
            });

            contexto.SaveChanges();

        }

the whole point is that I have another call Deny which is the same way passed, the parameters like this

[Route("{id}/{value}")]
        public void AtualizaNegarLiberacao(int id, string value)
        {
            var lista = contexto.Liberacoes
                        .Where(l => l.IdOrcamento == id)
                        .ToList();

            lista.ForEach(f =>
            {
                f.FlagLiberacao = 2;
                f.AutorizouReceberAtrazado = value;
            });

            contexto.SaveChanges();

        }

how do I configure the routes for each service, it take the right route.

1 answer

1

Prefix one of the routes (or both) with a unique name.

For example:

[Route("Negar/{id}/{value}")]
public void AtualizaNegarLiberacao(int id, string value) { }
  • LINQ and the call goes: dominio/api/controller/negar/id/value?

  • @pnet This method is not from the same controller (AtualizaController) of the other?

  • No, they’re different. I don’t know why the bug. I have Actualizcontroller and Negarcontroller

Browser other questions tagged

You are not signed in. Login or sign up in order to post.