发布到IIS,设置环境变量 [英] Publish to IIS, setting Environment Variable
问题描述
阅读这两个问题/答案我能够在IIS 8.5服务器上运行Asp.net 5应用程序。
Reading these two questions/answers I was able to run an Asp.net 5 app on IIS 8.5 server.
Asp.net vNext早期测试版发布到Windows服务器的IIS
问题是Web应用程序仍在使用 env.EnvironmentName
使用值开发
即使在IIS上运行。
The problem is that the web app is still using env.EnvironmentName
with value Development
even when run on IIS.
另外,我想运行同一个Web的两个版本(暂存,生产)在同一台服务器上,所以我需要一种方法来为每个Web单独设置变量。
Also, I want to run two versions of the same Web (Staging, Production) on the same server, so I need a method to set the variable for each Web separately.
如何做到这一点?
推荐答案
这个答案最初是为ASP.NET Core RC1编写的。在RC2中,ASP.NET Core从通用的httpPlafrom处理程序转移到aspnetCore特定的处理程序。请注意,步骤3取决于您使用的ASP.NET Core的版本。
This answer was originally written for ASP.NET Core RC1. In RC2 ASP.NET Core moved from generic httpPlafrom handler to aspnetCore specific one. Note that step 3 depends on what version of ASP.NET Core you are using.
可以设置ASP.NET核心项目的环境变量,而无需设置环境用户或必须创建多个命令条目的变量。
Turns out environment variables for ASP.NET Core projects can be set without having to set environment variables for user or having to create multiple commands entries.
- 转到IIS中的应用程序并选择
配置编辑器
。 - 选择
配置编辑器
- 选择
system.webServer / aspNetCore
(RC2和RTM)或system.webServer / httpPlatform
(RC1)inSection
combobox - 在
From $ c中选择
Applicationhost.config ...
$ c> combobox。 - 点击
enviromentVariables
元素并打开编辑窗口。 - 设置您的环境变量。
- 关闭窗口并单击应用。
- 完成
- Go to your application in IIS and choose
Configuration Editor
. - Select
Configuration Editor
- Choose
system.webServer/aspNetCore
(RC2 and RTM) orsystem.webServer/httpPlatform
(RC1) inSection
combobox - Choose
Applicationhost.config ...
inFrom
combobox. - Click on
enviromentVariables
element and open edit window. - Set your environment variables.
- Close the window and click Apply.
- Done
这样您就不必为池创建特殊用户或在其中创建额外的命令条目 project.json
。
此外,为每个环境添加特殊命令会中断构建一次,多次部署,因为您必须分别为每个环境调用 dnu publish
,而不是发布一次并多次部署产生的工件。
This way you do not have to create special users for your pool or create extra commands entries in project.json
.
Also, adding special commands for each environment breaks "build once, deploy many times" as you will have to call dnu publish
separately for each environment, instead of publish once and deploying resulting artifact many times.
更新了RC2和RTM,感谢Mark G和Tredder。
Updated for RC2 and RTM, thanks to Mark G and tredder.
这篇关于发布到IIS,设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!