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

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. 转 关于HTTP和HTTPS的区别

    关于HTTP和HTTPS的区别 运维猿 2018-12-01 07:30:00 一 HTTP和HTTPS的基本概念 1.HTTP:是互联网上应用最为广泛的一种网络协议,是一个客户端和服务器端请求和应答 ...

  2. python-面向对象中的特殊方法 ,反射,与单例模式

    二,面相对象的特殊成员及相关内置函数 2.1 isinstance与issubclass isinstance(obj,cls)检查是否obj是否是类 cls 的对象 class A: pass cl ...

  3. ubuntu中搭建基本的开发环境

    1.搭建基本开发环境: sudo apt-get install build-essential 2.安装语法.词法分析器 sudo apt-get install bison flex 3.安装C函 ...

  4. 聊聊redis实际运用及骚操作

    前言 聊起 redis 咱们大部分后端猿应该都不陌生,或多或少都用过.甚至大部分前端猿都知道. 数据结构: string. hash. list. set (无序集合). setsorted(有序集合 ...

  5. PHP操作XML方法之 XML Expat Parser

    XML Expat Parser 简介 此PHP扩展实现了使用PHP支持JamesClark编写的expat.此工具包可解析(但不能验证)XML文档.它支持PHP所提供的3种字符编码:US-ASCII ...

  6. ionic3 图片(轮播)预览 ionic-gallary-modal组件使用方法

    一.效果展示 使用方法: 1.npm安装ionic-gallary-modal扩展模块 npm install ionic-gallery-modal --save 2.在app.module.ts根 ...

  7. 【转载】vue install报错run `npm audit fix` to fix them, or `npm audit` for details html

    原链接https://www.jianshu.com/p/60591cfc6952 执行npm install 出现如下提醒 added 253 packages from 162 contribut ...

  8. Install ncurses (ncurses-devel) and try again

    apt install libncurses5-dev libncursesw5-dev

  9. Codeforces 1148F Foo Fighters 贪心

    题意:给你若干个数对,每个数对有两个属性,一个属性是权值,一个属性是位标志,假设这些数对的的权值和是sum,你可以选择一个二进制数s,与所有的数对的位标志按位与,如果按位与之后的位标志有奇数个1,那么 ...

  10. javascript笔记 (持续更新)

    1. 语言主要分为两大类:编译型语言和解释型语言. 对于静态语言来说(如Java.C++.C),处理上述这些事情的叫编译器(Compiler),相应地对于JavaScript这样的动态语言则叫解释器( ...