首页 > 解决方案 > IIS Express 路由在 Visual Sudio 2019 中无法正常工作

问题描述

我正在使用 Visual Studio 2019,当我通过 postman 运行解决方案IIS Express并向我的方法发送请求时,它返回404 status codedotnet command但是当我在 PowerShell 中运行我的解决方案时,该应用程序可以正常运行并返回OK 响应

我认为我的代码是正确的,因为当我使用 运行它时它可以正常工作dotnet command,但是我找不到解决此问题的方法。

我试图更改 SSL 端口launchSettings.json,我尝试使用 http 和 https 发送请求,但它们都不起作用。IIS Express或有什么问题Visual Studio吗?

    "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://localhost:6321/docs",
      "sslPort": 44444
    }
    [Route("api/[controller]")]
    public class ContentManagerController : Controller
    {
        [HttpPost]
        [Route("add")]
        public ContentManagerResponse AddSlider([FromBody]RequestClass request)
        {
            //some code
        }
    }

路由是http://localhost:6321/api/ContentManager/addhttps://localhost:44444/api/ContentManager/add

标签: c#asp.net.netvisual-studio.net-core

解决方案


针对您的特定情况的解决方案是更改launchSettings.json.

"applicationUrl": "http://localhost:6321/" 

推荐阅读