ASP.NET Core Web API中的launchSettings.json介绍

javascript 复制代码
{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:48930",
      "sslPort": 44300
    }
  },
  "profiles": {
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "http://localhost:5299",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "https://localhost:7107;http://localhost:5299",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

1. 全局设置:iisSettings

javascript 复制代码
"iisSettings": {
  "windowsAuthentication": false,
  "anonymousAuthentication": true,
  "iisExpress": {
    "applicationUrl": "http://localhost:48930",
    "sslPort": 44300
  }
}
  • 配置 IIS Express (Visual Studio 内置的轻量 Web 服务器)的行为:
    • windowsAuthentication: false → 禁用 Windows 身份认证
    • anonymousAuthentication: true → 启用匿名访问(任何人都能访问)
    • applicationUrl: IIS Express 启动时使用的 HTTP 地址
    • sslPort: HTTPS 端口(用于启用 SSL)

2. 启动配置:profiles

定义了 多个启动方式(Profiles),你可以在 Visual Studio 的启动按钮下拉菜单中选择:

javascript 复制代码
"http": {
  "commandName": "Project",
  "dotnetRunMessages": true,
  "launchBrowser": true,
  "launchUrl": "swagger",
  "applicationUrl": "http://localhost:5299",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
}
  • 使用 Kestrel 服务器(非 IIS)启动项目
  • 启动后自动打开浏览器,访问 http://localhost:5299/swagger
  • 仅监听 HTTP(无 HTTPS)
  • 设置环境变量:ASPNETCORE_ENVIRONMENT=Development(启用开发模式,如 Swagger)

Profile 2: "http"

javascript 复制代码
"http": {
  "commandName": "Project",
  "dotnetRunMessages": true,
  "launchBrowser": true,
  "launchUrl": "swagger",
  "applicationUrl": "http://localhost:5299",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
}
  • 使用 Kestrel 服务器(非 IIS)启动项目
  • 启动后自动打开浏览器,访问 http://localhost:5299/swagger
  • 仅监听 HTTP(无 HTTPS)
  • 设置环境变量:ASPNETCORE_ENVIRONMENT=Development(启用开发模式,如 Swagger)

Profile 2: "https"

javascript 复制代码
"https": {
  "commandName": "Project",
  "dotnetRunMessages": true,
  "launchBrowser": true,
  "launchUrl": "swagger",
  "applicationUrl": "https://localhost:7107;http://localhost:5299",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
}
  • 同样使用 Kestrel 启动
  • 同时监听 HTTPS(7107)和 HTTP(5299)
  • 浏览器默认打开 HTTPS 地址(因为 launchUrl 是相对路径,会优先用 HTTPS)
  • 这就是为什么你之前看到程序尝试连接 7188(类似端口)------因为启用了 HTTPS!

IIS 站点绑定配置

  1. 打开 IIS 管理器
  2. 添加网站:
    • 物理路径 :指向你的 publish 文件夹
    • 绑定
      • 类型:http
      • IP 地址:全部未分配 (即 *
      • 端口:8080
      • 主机名:留空

部署到 IIS 时,这些修改完全不影响生产环境,因为 launchSettings.json 不会被使用。

如果只是本机调试 只需要修改

javascript 复制代码
 "profiles": {
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "http://localhost:8080;http://10.167.199.106:8080", // 👈 关键修改!
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
相关推荐
上海合宙LuatOS5 天前
LuatOS核心库API——【json 】json 生成和解析库
java·前端·网络·单片机·嵌入式硬件·物联网·json
敲代码的柯基5 天前
一篇文章理解tsconfig.json和vue.config.js
javascript·vue.js·json
万物得其道者成6 天前
前端大整数精度丢失:一次踩坑后的实战解决方案(`json-bigint`)
前端·json
Ai runner6 天前
Show call stack in perfetto from json input
java·前端·json
ID_180079054736 天前
淘宝商品详情API请求的全场景,带json数据参考
服务器·数据库·json
开开心心_Every6 天前
音频格式互转工具,支持Mp3ApeWavFlac互转
linux·运维·服务器·typescript·edge·pdf·asp.net
恒云客7 天前
python uv debug launch.json
数据库·python·json
wanderist.7 天前
从 TCP 到 JSON:一次 FastAPI + LLM 生产环境 “Unexpected end of JSON input” 的底层剖析
tcp/ip·json·fastapi
享誉霸王8 天前
15、告别混乱!Vue3复杂项目的规范搭建与基础库封装实战
前端·javascript·vue.js·前端框架·json·firefox·html5
今心上8 天前
关于json的理解测试!!
开发语言·json