新建测试、正式环境下所用的 配置信息文件

appsettings.Development.json 文件信息:

{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"db": {
"mysql": {
"conStr": "xxxxxxxxxxxxxxxxx", //测试 "providerName": "MySql.Data.MySqlClient"
}, "redis": {
"conStr": "xxxxxxxxxxxxxxxxx", //测试 "dbId": "3"
}
}, "ThOcUrl": "xxxxxxxxxxxxxxxxx", //测试
"ThSftpInfo": "xxxxxxxxxxxxxxxxx", //测试
"ThFileUrl": "xxxxxxxxxxxxxxxxx" //测试 }

加入相关nuget引用

添加获取配置信息帮助类

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
using Microsoft.Extensions.DependencyInjection; namespace YanWenCore.ThregGoods.Common
{
public static class MyServiceProvider
{
public static IServiceProvider ServiceProvider
{
get; set;
}
} public class AppSettingHelper
{
//根据环境变量配置获取json文件的名称
private static readonly string AppSettingName = String.Format("appsettings.{0}.json", MyServiceProvider.ServiceProvider.GetRequiredService<IHostingEnvironment>().EnvironmentName); private static IConfigurationRoot configR;
static AppSettingHelper()
{
var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(AppSettingName);
configR = builder.Build();
} public static IConfigurationRoot GetRotConfig()
{
if (configR == null)
{
configR = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(AppSettingName).Build();
}
return configR;
} //Mysql连接
public static string MysqlConnectionStringSettings
{
get
{
return GetRotConfig().GetSection("db").GetSection("mysql").GetSection("conStr").Value;
}
} //Redis连接信息
public static string RedisConnectionStringSettings
{
get
{
return GetRotConfig().GetSection("db").GetSection("redis").GetSection("conStr").Value;
}
} //OC平台接口地址
public static string GetbatteryCertUrl
{
get
{
return GetRotConfig().GetSection("ThOcUrl").Value;
}
} //sftp服务器信息
public static string ThSftpInfo
{
get
{
return GetRotConfig().GetSection("ThSftpInfo").Value;
}
} //文件服务器地址
public static string ThFileUrl
{
get
{
return GetRotConfig().GetSection("ThFileUrl").Value;
}
} } }  

应用程序期间提供初始化提供服务容器的对象

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{ app.UseExceptionHandler("/Error");
}
MyServiceProvider.ServiceProvider = app.ApplicationServices;
}

执行docker run 之前,设置环境变量

set ASPNETCORE_ENVIRONMENT= Development

.net core 根据环境变量区分正式、测试 配置文件的更多相关文章

  1. JAVA_SE基础——2.环境变量的配置&测试JDK

    哈喽,利用晚上的空余时间再写篇心的~~~  谢谢大家 前一篇文章 JAVA_SE基础--JDK&JRE下载及安装http://blog.csdn.net/thescript_j/article ...

  2. ASP.NET Core使用环境变量

    前言 通常在应用程序开发到正式上线,在这个过程中我们会分为多个阶段,通常会有 开发.测试.以及正式环境等.每个环境的参数配置我们会使用不同的参数,因此呢,在ASP.NET Core中就提供了相关的环境 ...

  3. 在ASP.NET Core配置环境变量和启动设置

    在这一部分内容中,我们来讨论ASP.NET Core中的一个新功能:环境变量和启动设置,它将开发过程中的调试和测试变的更加简单.我们只需要简单的修改配置文件,就可以实现开发.预演.生产环境的切换. A ...

  4. ASP .NET CORE 根据环境变量支持多个 appsettings.json

    0.背景 在开发项目的过程当中,生产环境与调试环境的配置肯定是不一样的.拿个最简单的例子来说,比如连接字符串这种东西,调试环境肯定是不能连接生产数据库的.在之前的话,这种情况只能说是你 COPY 两个 ...

  5. ASP.NET Core配置环境变量和启动设置

    在这一部分内容中,我们来讨论ASP.NET Core中的一个新功能:环境变量和启动设置,它将开发过程中的调试和测试变的更加简单.我们只需要简单的修改配置文件,就可以实现开发.预演.生产环境的切换. A ...

  6. [转]ASP.NET Core配置环境变量和启动设置

    本文转自:https://www.cnblogs.com/tdfblog/p/Environments-LaunchSettings-in-Asp-Net-Core.html 在这一部分内容中,我们来 ...

  7. .net core 中环境变量的配置

    配置文件: Properties目录下的launchSettings.json IISExpress配置 "ASPNET_ENV": "EnvironmentOne&qu ...

  8. Web开发之tomcat配置及使用(环境变量设置及测试,一个简单的web应用实例)

    Tomcat的配置及测试: 第一步:下载tomcat,然后解压到任意盘符 第二步:配置系统环境变量 tomcat解压到的D盘 (路径为: D:\tomcat), 配置环境变量: 启动tomcat需要两 ...

  9. [.net core] 12.环境变量

    异常给开发人员提供了很大好的排错功能. 但是其背后的技术细节很复杂,会损耗性能,也会使.net core web app更容易被反派攻击. 于是我们要学会使用环境变量, 通过环境变量,控制一些逻辑 当 ...

随机推荐

  1. 引用so动态链接库的方法

    from ctypes import cdll lib = cdll.LoadLibrary('/home/zhengli/test/test.so') lib.func() 总结: 1.引用ctyp ...

  2. ant的安装和使用

    1.ant的安装 1.1 添加环境变量:ANT_HOME=D:\software\ant\apache-ant-1.10.1 在path中添加:%ANT_HOME%\bin 1.2 测试是否安装成功 ...

  3. PAT 乙级练习题1001 害死人不偿命的(3n+1)猜想 (15)

    1001. 害死人不偿命的(3n+1)猜想 (15) 卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去, ...

  4. react踩坑

    1.列表渲染一定要注意key的唯一性,不然会导致页面只更新部分的bug graphVertexConfigList.data.map((item, index) => { return < ...

  5. linux常用命令-1系统相关命令

    hostname #计算机名 passwd #修改密码 reboot #重启 shutdown –r now #立刻重启(root用户使用) shutdown –r 10 #过10分钟自动重启(roo ...

  6. androidstudio 2.3.3 jni过程汇总(1):1、自己编写c文件并使用(原)

    1.编写java代码,指定lib和native方法.package com.taven.myapplication; package com.taven.myapplication; import a ...

  7. vue 点击切换图标

    <div @click="showImg" class="showSearch"> <img class="header_img&q ...

  8. Oracle数据库创建与连接

    一.Oracle数据库的安装 1.下载Oracle数据库 网址:Oracle 数据库软件下载 | Oracle 技术网 | Oracle 由于需要注册,所以我就没有采用这种下载方式,  右击该网页查看 ...

  9. QDomDocument::clear()的调用,会导致关闭程序时崩溃!!!

    //读一份xml前,先清理m_Doc[QDomDocument] bool XmlIO::xmlRead(QString &errmsg) { m_mutex.lock(); // m_Doc ...

  10. mac终端命令--自动补全

    1.打开nano编辑器 输入命令 nano .inputrc,回车,打开nano编辑器 2.在nano编辑器中输入如下命令: set completion-ignore-case on set sho ...