Problem accessing the Controller

Asked

Viewed 38 times

1

Apicontroller

[Produces("application/json")]
[Route("api/[controller]")]
public class ClienteController : Controller
{
    private IClienteRepository _ClienteRepository;

    public ClienteController(IClienteRepository clienteRepository)
    {
        _ClienteRepository = clienteRepository;
    }

    [HttpPost]
    public IEnumerable<Cliente> Get()
    {
        return _ClienteRepository.Get(x => x.ClienteId > 0);
    }
}

Stratup

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddTransient<IClienteRepository, ClienteRepository>();
        services.AddMvc();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseDefaultFiles();
        app.UseStaticFiles();
        app.UseMvc();
    }
}

Launchsettings.json

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:52676/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/cliente",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Safra.AberturaDeContas.Api": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/cliente",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:52677/"
    }
  }
}

Error while climbing the api by accessing http://localhost:52676/api/client:

This localhost page can’t be found

  • 1

    It seems your controller has no Get method, only one Post, and via browser, you do a GET.

  • Using Postman with the Post method I’m also not getting the return

  • the status code is being 200 ?

  • using the URL = http://localhost:52676/Client/Get clients and http://localhost:52676/api/Client/Get clients, Return = 404 Not Found

  • 1

    I got @Lucas Brogni, I used the URL: http://localhost:52676/Client/Get clients and I memorized my method [HttpPost]&#xA; [Route("/Cliente/ObterClientes")]&#xA; public IEnumerable<Cliente> ObterClientes()&#xA; {&#xA; return _ClienteRepository.Get(x => x.ClienteId > 0);&#xA; }

No answers

Browser other questions tagged

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