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"
      }
    },
相关推荐
goehou1 天前
LLM 结构化输出全解:从 Prompt 约束到 Schema 硬保证,三层实现怎么选
ai·llm·json·agent·教程·结构化输出
独立开发者阿乐1 天前
结构化数据 JSON-LD 实战:让 AI 读懂你的网页
人工智能·json·结构化数据·geo优化·json-ld·ai收录·faqpage
liangshanbo12153 天前
高级前端面试题:package.json 常见字段
前端·json
梦帮科技3 天前
【3.0修订版】创世与节点工程:genesis.json 与 node.toml 解剖
数据结构·算法·json·去中心化·区块链·智能合约·信任链
weixin_440730504 天前
内置函数、json文本、pickle二进制
开发语言·python·json
念越4 天前
接口自动化测试从入门到实战:接口用例设计、Requests、Pytest、YAML、JSON Schema 与 Allure 报告
python·测试工具·自动化·json·pytest
QQ_21696290964 天前
基于C#(Asp.net)电竞陪玩信息管理系统的设计与实现
java·大数据·spring boot·微信小程序·c#·云计算·asp.net
福兮说5 天前
前后端算的 MD5、SHA-256 对不上?编码、换行、BOM、HMAC、JSON 顺序,八个原因逐个实测
前端·javascript·node.js·json·哈希算法
wdfk_prog5 天前
Wi-Fi Direct 源码分析(11):P2P-GROUP-STARTED 之后——Group Interface、IP 配置与真实数据通路
运维·服务器·网络协议·tcp/ip·asp.net·p2p·wifi-direct
网络毒刘6 天前
MCP 从 0 接入 Cursor:mcp.json 安装配置到最小调用与常见报错
json