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 站点绑定配置
- 打开 IIS 管理器
- 添加网站:
- 物理路径 :指向你的
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"
}
},