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"
      }
    },
相关推荐
电商API&Tina2 小时前
【电商API接口】开发者一站式电商API接入说明
大数据·数据库·人工智能·云计算·json
消失的旧时光-19434 小时前
Android 面试高频:JSON 文件、大数据存储与断电安全(从原理到工程实践)
android·面试·json
ChoSeitaku13 小时前
NO.4|protobuf网络版通讯录|httplib|JSON、XML、ProtoBuf对比
xml·json
青衫客3614 小时前
浅谈 Java 后端对象映射:从 JSON → VO → Entity 的原理与实践
java·json
qqxhb1 天前
11|结构化输出:为什么 JSON 能让系统更稳定
json·ai编程·结构化·规范模板
小黑要努力1 天前
json-c安装以及amixer使用
linux·运维·json
bugcome_com2 天前
ASP.NET Web Forms 零基础入门教程
后端·asp.net
William_cl2 天前
C# ASP.NET Identity 授权实战:[Authorize (Roles=“Admin“)] 仅管理员访问(避坑 + 图解)
开发语言·c#·asp.net
听风者一号2 天前
cssMoudle生成器
前端·javascript·json
bugcome_com2 天前
【ASP.NET Web Pages】页面布局核心实战:从复用性到安全性,打造一致化网站界面
前端·后端·asp.net