asp.net-core - 如何在 ASP.NET Core 3.1 应用程序中根据 URL 进行单独的 IIS Express 配置?
问题描述
我有一个项目,我想在 IIS 服务器上的两个不同地址发布:https://domain/test1/
和https://domain/test2/
. 根据我发布的地址,我想为我的项目设置不同的配置设置,为简化起见,假设配置是一个 entry email
。因此,对于https://domain/test1/
我想要配置的地址email: test1@test1.com
和https://domain/test2/
, email: test2@test2.com
。
我尝试更改launchSettings.json
文件中的配置,但我无法添加具有相同名称的条目,如果我更改条目的名称,那么它将不知道使用 IISExpress 发布它。
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"applicationUrl": "https://domain/test1",
"email": "test1@test1.com",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"applicationUrl": "https://domain/test2",
"email": "test2@test2.com",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
如何根据 ASP.NET Core 3.1 中的当前 URL 地址进行单独配置?
解决方案
据我所知,launchSettings.json文件只用在本地开发机上,没有部署。它仅由 Visual Studio 使用。
所以如果你在launchSettings.json中设置了email设置,就不会部署到生产服务器,也不会被使用。
此外,正如 Lex 所说,没有这样的功能可以满足您的要求。
我建议您可以考虑使用 appsetting.json 和 Environment 变量来满足您的要求。
您可以使用不同的环境创建多个 appsetting.json。
发布后,您可以打开applicationHost.config
指定站点位置并设置不同的环境变量,如下所示。
注意:此解决方法仅适用于不同的 IIS 网站名称,路径为 IIS 网站名称。
applicationHost.config
路径:C:\Windows\System32\inetsrv\config\
。
<location path="domainA">
<system.webServer>
<aspNetCore>
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Staging" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
<location path="domainB">
<system.webServer>
<aspNetCore>
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
推荐阅读
- opencv - opencv python的namedwindow中间有黑色层
- flutter - Flutter - 在 Border 的情况下,行项目空间随着页面缩放而增加
- java - 如何减少启动画面时间
- data-visualization - TypeError: distplot() 得到了一个意外的关键字参数“x”(或“hue”)
- asp.net - 使用 Angular 的 ASP.NET Core 中的 CSRF 令牌验证失败
- reactjs - 网站工作,但 Facebook 调试器 Curl 错误:28 (OPERATION_TIMEOUTED)
- android - 地图上的 Android 2D 游戏
- flutter - 无法摆脱 Widget 中的垂直边距
- xcode - 如何在不弄乱引用的情况下移动 xcode 文件的保存位置
- java - 如何从 java main 方法存储/返回字符串值?