C# launchSettings.json launchUrl不';t工作“;api/values";

C# launchSettings.json launchUrl不';t工作“;api/values";,c#,asp.net,asp.net-core,asp.net-core-webapi,.net-core-2.2,C#,Asp.net,Asp.net Core,Asp.net Core Webapi,.net Core 2.2,我试图改变路线,但程序被这个url卡住了 我读了这本书 每个人都写同样的东西,但不是为我工作 我的launchSetting.json文件是 { "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": {

我试图改变路线,但程序被这个url卡住了

我读了这本书

每个人都写同样的东西,但不是为我工作

我的
launchSetting.json
文件是

{  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:54650",
      "sslPort": 44382
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "ShoppingBasketAPI": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}
我试图更改app.UseMvc()

这也不起作用。
api/values
来自哪里?我不明白

我的控制器属性路由是
[路由(“api/[控制器]/[操作]”)

当您创建新的ASP.Net核心Web api项目时,您将看到在项目属性中有
启动浏览器
设置,设置为
api/values
路径。因此,您可以将其更改为所需的url,也可以在launchSetting.json文件中进行更改

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://localhost:54356",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "WebApplication4": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "applicationUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}
所以你们会在配置文件部分看到2个配置文件。一种是IIS express(当使用Visual Studio运行代码时)和WebApplication4(当使用dotnet运行项目时),这样您就可以更改为

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://localhost:54356",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "WebApplication4": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

因此,当您使用VS运行项目或
dotnet运行时,
命令总是首先服务于招摇过市的url。

问题在于Visual Studio for Mac。我能够获得正确的url来运行chance
Run With>Custom Configuration>运行操作-->Debug.Net Core Debugger

我正在使用VSCode,并且在Windows上也发生了同样的情况。 我只是在这里补充一点答案

我曾经尝试过VS2019,它在那个IDE中工作,所以它应该与VSCode有关。 我已经寻找了其他答案,我找到了这个

解决我的问题的方法是转到.vscode/launch.json文件并附加:

         "launchBrowser": {
            "enabled": true,
            "args": "${auto-detect-url}",
            "windows": {
                "command": "cmd.exe",
                "args": "/C start ${auto-detect-url}/swagger"
            }

正如Anton Dremin所描述的,只需将上述内容添加到配置部分。

是的,但这两项都不起作用。我仍然有api/价值观路线。这可能是因为我使用macOS吗?@HaktanEnesBiçer我不这么认为。尝试在项目中搜索api/值,以查看是否还有包含该值的代码?我的方法非常有效。我觉得代码有问题,我发现了问题。这是因为visual studio mac。我在“api/values”之前搜索过,但找不到任何代码。