C# ASP.NET Core 2.2 Web API未命中任何配置的路由,这是为什么?

C# ASP.NET Core 2.2 Web API未命中任何配置的路由,这是为什么?,c#,asp.net-web-api,asp.net-core,.net-core,C#,Asp.net Web Api,Asp.net Core,.net Core,我创建的BaseController如下所示 `[ApiController] public class MoviesPlaceBaseController : ControllerBase { protected readonly IMoviesPlaceSupervisor _moviesPlaceSupervisor; public MoviesPlaceBaseController(IMoviesPlaceSupervisor moviesPlaceSuperv

我创建的BaseController如下所示

`[ApiController]
  public class MoviesPlaceBaseController : ControllerBase
  {
    protected readonly IMoviesPlaceSupervisor _moviesPlaceSupervisor;

    public MoviesPlaceBaseController(IMoviesPlaceSupervisor moviesPlaceSupervisor)    
    {
        _moviesPlaceSupervisor = moviesPlaceSupervisor;
    }`
在我的“PostController”中,我从基本控制器类派生,它看起来像这样

`    [Route("[controller]")]
    [Produces("application/json")]
    public class PostController : MoviesPlaceBaseController
    {
      public PostController(IMoviesPlaceSupervisor supervisor) : base (supervisor){ }

        // GET api/post
        [HttpGet]
        [Produces(typeof(List<PostViewModel>))]
        public async Task<ActionResult<List<PostViewModel>>> Get(CancellationToken ct = default(CancellationToken))
        {
          return new ObjectResult(await _moviesPlaceSupervisor.GetAllPostsAsync(ct));
        }`
`"MoviesPlaceAPI": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/",
      "applicationUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }`
` public void ConfigureServices(IServiceCollection services)
    {
      services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

      services.AddConnectionProvider(Configuration)
        .ConfigureSupervisor()
        .AddMiddleware()
        .AddCorsConfiguration()
        .ConfigureRepositories();
    }`
我的Startup.cs ConfigureServices如下所示

`    [Route("[controller]")]
    [Produces("application/json")]
    public class PostController : MoviesPlaceBaseController
    {
      public PostController(IMoviesPlaceSupervisor supervisor) : base (supervisor){ }

        // GET api/post
        [HttpGet]
        [Produces(typeof(List<PostViewModel>))]
        public async Task<ActionResult<List<PostViewModel>>> Get(CancellationToken ct = default(CancellationToken))
        {
          return new ObjectResult(await _moviesPlaceSupervisor.GetAllPostsAsync(ct));
        }`
`"MoviesPlaceAPI": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/",
      "applicationUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }`
` public void ConfigureServices(IServiceCollection services)
    {
      services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

      services.AddConnectionProvider(Configuration)
        .ConfigureSupervisor()
        .AddMiddleware()
        .AddCorsConfiguration()
        .ConfigureRepositories();
    }`

当运行我的应用程序时,我不能点击我的api/post路径。当我在该操作中设置断点并运行应用程序时,断点表示其“未验证”。我试着做api/post和api/post。在controller类中,我删除了路由[“controller”],只使用了controller“post”的名称,但事情是一样的。奇怪的是,即使我的应用程序中不再存在该控制器,我仍然可以很好地命中api/值。我不知道发生了什么,有人能解释一下吗。

我在执行clean-then-build时将我的项目从asp.net core 2.1升级到了2.2。它并没有完全摆脱以前编译的代码。我的launch.json文件仍然指向Debug/netcoreapp.2.1。。。将其更改为2.2后,一切都开始按预期工作。

您可能需要清理SOUTION->清除bin文件夹,重新构建您将
ValuesController
重命名为
PostController
?我忘了添加我这样做的内容,不幸的是我得到了同样的结果。很奇怪。推荐信还在某处。是的,我做了。我将值控制器重命名为post控制器。如果类名更改,而文件名本身也更改了,这会产生怎样的影响。能否添加一个新的控制器,将代码移动到并尝试(删除旧的控制器)