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"
      }
    },
相关推荐
赵庆明老师1 天前
Vben精讲:21-详解web-antd:tsconfig.json
前端·json·vim
红叶舞3 天前
成数据绑定对象,在应用程序中处理完数据后,将更新的数据序列化为JSON传回远端服务器,很多移动应用使用了这种模式处理服务器端的数据。 ...
运维·服务器·json
name好难取诶3 天前
解析请求体内容(如 JSON、表单数据、XML 等) 将原始数据转换为 Python 数据结构 使转换后的数据可在 request. ...
xml·python·json
米码收割机3 天前
【C#】ASP.NET Web 车辆信息管理系统(源码+文档)【独一无二】
前端·c#·asp.net
gcw10243 天前
JSONMe 简觅JSON 工具
json·json格式化·json可视化·json美化·json校验·好用的json工具·json编辑
北北牌屈四巴格!4 天前
whistle自定义修改接口返回值内容
前端·json
丙氨酸長鏈4 天前
WPF 引用 ASP.NET Core 的 AOT 版本
后端·asp.net·wpf
SQDN4 天前
Chatbox 1.22.1 获取不到模型?先验 /models,再对齐精确 model ID
人工智能·测试工具·机器学习·chatgpt·json
SunnyDays10114 天前
Python 将 Excel(XLS/XLSX)转换为 JSON:导出工作簿、工作表、单元格区域与自定义 JSON 结构
python·json·excel·excel 转 json·导出 excel 到 json·xlsx 转 json·xls 转 json
刘小八5 天前
Spring AI 结构化输出:稳定生成可校验的业务 JSON
人工智能·spring·json