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

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. 关于pandas

    axis轴,axis=0为逐行,axis=1为逐列

  2. Darknet YOLOv3 on Jetson Nano

    推荐比较好的博客:https://ai4sig.org/2019/06/jetson-nano-darknet-yolov3/ 用的AlexeyAB的版本,并且给出了yolov3和tiny的效果对比. ...

  3. 使用MySQL Workbench查询超时的错误

    MySQL Workbench是MySQL提供的连接工具,一直在用它.但是今天运行了一个SQL缺报出如下的错误: errcode 2013 lost connection to mysql serve ...

  4. Spring项目下js文件无法引用

    问题:最近练习spring-mvc框架的时候,引用了jQuery,但是运行的时候,jQuery做的事情都没有响应,代码也没有任何报错,在网上找了一下,发现是由于spring配制的是/,所有的资源都被屏 ...

  5. WPF 从服务器下载文件

    1.先获取服务器下载地址,给出要下载到的目标地址 public void DownloadFileFromServer() { string serverFilePath = "http:/ ...

  6. string参考

    #include <iostream> #include <string.h> class string { private: char *data; public: stri ...

  7. Java自定义注解Annotation的使用

    从 jdk5开始,Java增加了对元数据的支持,也就是Annotation,Annotation其实就是对代码的一种特殊标记,这些标记可以在编译,类加载和运行时被读取,并执行相应的处理.当然刚刚说了, ...

  8. leetcode-161周赛-5249-移除无效的括号

    题目描述: 自己的提交:O(N) class Solution: def minRemoveToMakeValid(self, s: str) -> str: #from collections ...

  9. 操作系统之IO管理

    IO系统结构 设备的分类 按数据组织分 块设备: 信息的存取总是以数据块为单位. 它属于有结构设备,如磁盘等. 磁盘设备的基本特征是传输速率较高,以及可寻址,即对它可随机地读/写任一块. 字符设备: ...

  10. 8、iota枚举

    1.iota常量自动生成器,每一行,自动累加1 2.iota给常量赋值使用 3.如果iota遇到const,就会重置为0 4.可以可以只写一个iota 5.如果是同一行,值是一样的 // 09_iot ...