zoukankan      html  css  js  c++  java
  • [.net core] 12.环境变量

    异常给开发人员提供了很大好的排错功能.

    但是其背后的技术细节很复杂,会损耗性能,也会使.net core web app更容易被反派攻击.

    于是我们要学会使用环境变量, 通过环境变量,控制一些逻辑

    当在开发环境时,出现错误,跳转到开发人员看的异常页

    当在生产环境时,出现错误时 跳转到给用户看的错误页,

    .net core web app的环境 可以在计算机上设置,

    设置计算机的环境变量后要重启visual studio 才能生效.

    也可以在launchSettings.json 里设置,也可以不设置. 同时设置时, launchSettings.json的配置大于计算机上的环境变量

    当不设置时,默认使用product

    .net core web app默认支持三个环境

    1.开发环境 Development

    2.演示环境 Staging

    3.生产环境  Production

    在程序里可以依赖注入IHostingEnvironment 来使用

    IHostingEnvironment.IsDevelopment()
    
    IHostingEnvironment.IsStaging()
    
    IHostingEnvironment.IsProductiont()

    除了这三个环境变量,也可以用任意字符串来算定自己的环境变量比如heiheihei环境变量

    IHostingEnvironment.IsEnvironment("heiheihei")

    除此之外,使用

    IHostingEnvironment.EnvironmentName

    可以得到当前的环境变量 字符串.

  • 相关阅读:
    每日日报
    每日日报
    JAVA日报
    JAVA日报
    JAVA日报
    JAVA日报
    NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated"}
    2020.11.07
    2020.11.05
    2020.11.09
  • 原文地址:https://www.cnblogs.com/nocanstillbb/p/11298907.html
Copyright © 2011-2022 走看看