如何在生产环境中设置ASP.NET 5环境变量 [英] How to set ASP.NET 5 environment variables on production environment

查看:268
本文介绍了如何在生产环境中设置ASP.NET 5环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2015中,您可以在项目属性中设置以下变量: ASPNET_ENV 。如果您将其设置为开发,则可以使用以下方式:

In Visual Studio 2015 you set the following variable in project properties: ASPNET_ENV. If you set it to development then you can use:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseErrorPage();
    }
 }

IsDevelopment方法将检查 ASPNET_ENV 环境变量。现在,当您在Visual Studio 2015中时,这是非常好的开发。当您将Web应用程序发布到生产服务器上的IIS时,您可以如何设置 ASPNET_ENV 的值?

IsDevelopment method will check ASPNET_ENV environment variable. Now this is all good on development while you are in Visual Studio 2015. When you publish the web application to IIS on a production server how can you set the value for ASPNET_ENV?

我的服务器是Windows Server 2012

My server is Windows Server 2012

推荐答案

如果您使用IIS托管应用程序,可以在 web.config 文件中设置环境变量:

If you are using IIS to host your application, it's possible to set the environment variables in your web.configfile like this:

<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
    <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="QA" />
        <environmentVariable name="AnotherVariable" value="My Value" />
    </environmentVariables>
</aspNetCore>

这篇关于如何在生产环境中设置ASP.NET 5环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆