當運行一個 Asp.Net Core 應用的時候, WebHostBuilder 根據環境變量來判斷當前運行的是哪一個環境,多是 Development,Staging或者Production.你也能夠設置成隨便的一個字符串.web
這個連接將會告訴你 如何在各類平臺各類環境中設置環境變量.但若是你使用 IIS來代理 Asp.Net Core.你須要在 web.config 中設置環境變量ui
<configuration> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/> </handlers> <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"> <environmentVariables> <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" /> </environmentVariables> </aspNetCore> </system.webServer> </configuration>
你須要把如下內容添加到 web.configspa
<environmentVariables> <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" /> </environmentVariables>