• <tfoot id='L71Gx'></tfoot>

        <legend id='L71Gx'><style id='L71Gx'><dir id='L71Gx'><q id='L71Gx'></q></dir></style></legend>
          <bdo id='L71Gx'></bdo><ul id='L71Gx'></ul>
      1. <i id='L71Gx'><tr id='L71Gx'><dt id='L71Gx'><q id='L71Gx'><span id='L71Gx'><b id='L71Gx'><form id='L71Gx'><ins id='L71Gx'></ins><ul id='L71Gx'></ul><sub id='L71Gx'></sub></form><legend id='L71Gx'></legend><bdo id='L71Gx'><pre id='L71Gx'><center id='L71Gx'></center></pre></bdo></b><th id='L71Gx'></th></span></q></dt></tr></i><div id='L71Gx'><tfoot id='L71Gx'></tfoot><dl id='L71Gx'><fieldset id='L71Gx'></fieldset></dl></div>
      2. <small id='L71Gx'></small><noframes id='L71Gx'>

        在 ASP.NET Core 中读取环境变量

        时间:2023-07-11
      3. <legend id='kq8xV'><style id='kq8xV'><dir id='kq8xV'><q id='kq8xV'></q></dir></style></legend><tfoot id='kq8xV'></tfoot>

          <tbody id='kq8xV'></tbody>

        <small id='kq8xV'></small><noframes id='kq8xV'>

              <bdo id='kq8xV'></bdo><ul id='kq8xV'></ul>
              <i id='kq8xV'><tr id='kq8xV'><dt id='kq8xV'><q id='kq8xV'><span id='kq8xV'><b id='kq8xV'><form id='kq8xV'><ins id='kq8xV'></ins><ul id='kq8xV'></ul><sub id='kq8xV'></sub></form><legend id='kq8xV'></legend><bdo id='kq8xV'><pre id='kq8xV'><center id='kq8xV'></center></pre></bdo></b><th id='kq8xV'></th></span></q></dt></tr></i><div id='kq8xV'><tfoot id='kq8xV'></tfoot><dl id='kq8xV'><fieldset id='kq8xV'></fieldset></dl></div>

                  本文介绍了在 ASP.NET Core 中读取环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用 DNX 运行我的 ASP.NET Core 应用程序,我能够从命令行设置环境变量,然后像这样运行它:

                  Running my ASP.NET Core application using DNX, I was able to set environment variables from the command line and then run it like this:

                  set ASPNET_ENV = Production
                  dnx web
                  

                  在 1.0 中使用相同的方法:

                  Using the same approach in 1.0:

                  set ASPNETCORE_ENVIRONMENT = Production
                  dotnet run
                  

                  不起作用 - 应用程序似乎无法读取环境变量.

                  does not work - the application does not seem to be able to read environment variables.

                  Console.WriteLine(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"));
                  

                  返回空值

                  我错过了什么?

                  推荐答案

                  您的问题是 = 周围的空格.

                  Your problem is spaces around =.

                  这会起作用(在结束引用之前注意空格):

                  This will work (attention to space before closing quote):

                  Console.WriteLine(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT "));
                  

                  这段代码中ASPNETCORE_ENVIRONMENT后面的空格不是错字!问题中的问题是有额外的空间(在 SET... 中),因此您必须在 GetEnvironmentVariable() 中使用相同的空间.

                  The space after ASPNETCORE_ENVIRONMENT in this code is not a typo! The problem in the question was having extra space (in SET...), so you must use the same space in GetEnvironmentVariable().

                  如 Isantipov 在评论中所述,更好的解决方案是从 SET 命令中完全删除空格:

                  As noted by Isantipov in a comment, an even better solution is to remove the spaces entirely from the SET command:

                  set ASPNETCORE_ENVIRONMENT=Production
                  

                  这篇关于在 ASP.NET Core 中读取环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用依赖注入注入多个实现 下一篇:我应该使用 AddMvc 还是 AddMvcCore 进行 ASP.NET Core MVC 开发?

                  相关文章

                    <bdo id='Vz5Mo'></bdo><ul id='Vz5Mo'></ul>
                1. <legend id='Vz5Mo'><style id='Vz5Mo'><dir id='Vz5Mo'><q id='Vz5Mo'></q></dir></style></legend>

                    <small id='Vz5Mo'></small><noframes id='Vz5Mo'>

                  1. <i id='Vz5Mo'><tr id='Vz5Mo'><dt id='Vz5Mo'><q id='Vz5Mo'><span id='Vz5Mo'><b id='Vz5Mo'><form id='Vz5Mo'><ins id='Vz5Mo'></ins><ul id='Vz5Mo'></ul><sub id='Vz5Mo'></sub></form><legend id='Vz5Mo'></legend><bdo id='Vz5Mo'><pre id='Vz5Mo'><center id='Vz5Mo'></center></pre></bdo></b><th id='Vz5Mo'></th></span></q></dt></tr></i><div id='Vz5Mo'><tfoot id='Vz5Mo'></tfoot><dl id='Vz5Mo'><fieldset id='Vz5Mo'></fieldset></dl></div>

                  2. <tfoot id='Vz5Mo'></tfoot>