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"
      }
    },
相关推荐
Venuslite3 天前
从 Unexpected token < 到 Extra data:一次讲清 JSON 解析错误的排查思路
json
疯狂SQL9 天前
手写高性能在线 JSON 工具|Web Worker 工程化打包 + 语法自动修复 + 多语言代码生成实战
typescript·json·next.js·web worker·前端性能优化·esbuild·源码实战
terry60014 天前
5G视频短信服务商选型全攻略:通道资源、架构能力与成本评估2026最新标准
大数据·人工智能·5g·json·asp.net·信息与通信·数据库架构
前网易架构师-高司机14 天前
带标注的辣椒病叶数据集,识别率95.9%,可识别三种病害和健康叶子,9916张图,支持yolo,coco json,voc xml,文末有模型训练代码
yolo·json·数据集·病害·叶病·病叶·辣椒
PixelBai14 天前
JSON扁平化使用教程:从入门到精通
json
渔舟唱晚,雁阵惊寒15 天前
CSDN博客内容丢失如何恢复?
json
衣乌安、15 天前
JSON-RPC协议
网络协议·rpc·json
PixelBai15 天前
JSON过滤使用教程:从入门到精通
javascript·chrome·json
加号315 天前
【C#】VS2022 传统 ASP.NET Web 服务(.asmx)接口实现指南
前端·c#·asp.net