为什么 apicontroller 中的路由不起作用?

Kel*_*ckt 1 c# controller asp.net-core

我有一个名为“GebruikersController”的控制器类

当我使用“ https://localhost:5001/Gebruikers ”我得到正确的输出但是当我使用“ https://localhost:5001/api/GebruikerController/Gebruikers ”(它应该如何工作?)我得到一个空白页. 有谁能够帮助我?谢谢!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using RESTAPI.Data;
using RESTAPI.Data.Repositories;
using RESTAPI.DTOs;
using RESTAPI.Models;

namespace RESTAPI.Controllers
{
  [ApiConventionType(typeof(DefaultApiConventions))]
  [Produces("application/json")]
  [Route("api/[controller]")]
  [ApiController]
  public class GebruikersController : ControllerBase
  {
    private readonly IGebruikerRepository _gebruikerRepository;

    public GebruikersController(IGebruikerRepository context)
    {
            _gebruikerRepository = context;
    }

    // GET: api/Gebruikers
    /// <summary>
    /// Geeft alle gebruikers geordend op achternaam
    /// </summary>
    /// <returns>array van gebruikers</returns>
    [HttpGet("/Gebruikers")]
    public IEnumerable<Gebruiker> GetGebruikers()
    {
            return _gebruikerRepository.GetAlleGebruikers().OrderBy(d => d.Achternaam);
    }

    // GET: api/Gebruikers/5
    /// <summary>
    /// Geeft de gebruiker met het gegeven id terug
    /// </summary>
    /// <param name="id">het id van de gebruiker</param>
    /// <returns>De gebruiker</returns>
    [HttpGet("{id}")]
    public ActionResult<Gebruiker> GetGebruiker(int id)
    {
      Gebruiker gebruiker = _gebruikerRepository.GetBy(id);
      if (gebruiker == null) return NotFound();
      return gebruiker;
    }

  }
}
Run Code Online (Sandbox Code Playgroud)

Dmi*_*mov 5

尝试使用 https://localhost:5001/api/Gebruikers/Gebruikers 而不是 https://localhost:5001/api/GebruikerController/Gebruikers.

控制器”一词未写在 URL 中。