Configuration改由Startup.cs中获取
This commit is contained in:
@@ -304,3 +304,4 @@ __pycache__/
|
|||||||
# OpenCover UI analysis results
|
# OpenCover UI analysis results
|
||||||
OpenCover/
|
OpenCover/
|
||||||
COMCMS.Web/wwwroot/userfiles/
|
COMCMS.Web/wwwroot/userfiles/
|
||||||
|
/COMCMS.Web/COMCMS.Web.csproj.DotSettings
|
||||||
|
|||||||
@@ -22,10 +22,15 @@ namespace COMCMS.Common
|
|||||||
|
|
||||||
static Utils()
|
static Utils()
|
||||||
{
|
{
|
||||||
//ReloadOnChange = true 当appsettings.json被修改时重新加载
|
////ReloadOnChange = true 当appsettings.json被修改时重新加载
|
||||||
Configuration = new ConfigurationBuilder()
|
//Configuration = new ConfigurationBuilder()
|
||||||
.Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true })
|
//.Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true })
|
||||||
.Build();
|
//.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddUtils(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 静态变量
|
#region 静态变量
|
||||||
|
|||||||
@@ -283,7 +283,7 @@
|
|||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Update="appsettings.json">
|
<Content Update="appsettings.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,14 @@ namespace COMCMS.Web.Controllers
|
|||||||
{
|
{
|
||||||
public static IConfiguration Configuration { get; set; }
|
public static IConfiguration Configuration { get; set; }
|
||||||
public ConcurrentDictionary<string, string> AllSession = new ConcurrentDictionary<string, string>();
|
public ConcurrentDictionary<string, string> AllSession = new ConcurrentDictionary<string, string>();
|
||||||
public HomeController()
|
|
||||||
{
|
|
||||||
Configuration = new ConfigurationBuilder()
|
|
||||||
.Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true })
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
|
public HomeController(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
//Configuration = new ConfigurationBuilder()
|
||||||
|
// .SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
// .AddJsonFile("appsettings.json", optional: true, reloadOnChange : true)
|
||||||
|
// .Build();
|
||||||
|
Configuration = configuration;
|
||||||
}
|
}
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
@@ -89,7 +91,7 @@ namespace COMCMS.Web.Controllers
|
|||||||
|
|
||||||
public IActionResult Test2()
|
public IActionResult Test2()
|
||||||
{
|
{
|
||||||
var settings = "appsettings.json".GetFullPath();
|
var settings = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json");
|
||||||
var css2 = new ConfigurationBuilder().AddJsonFile(settings).Build().GetSection("connectionStrings");
|
var css2 = new ConfigurationBuilder().AddJsonFile(settings).Build().GetSection("connectionStrings");
|
||||||
|
|
||||||
string s = "";
|
string s = "";
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using Senparc.Weixin;
|
|||||||
using Senparc.Weixin.MP;
|
using Senparc.Weixin.MP;
|
||||||
using Senparc.Weixin.TenPay.V3;
|
using Senparc.Weixin.TenPay.V3;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace COMCMS.Web.Controllers
|
namespace COMCMS.Web.Controllers
|
||||||
@@ -124,5 +125,7 @@ namespace COMCMS.Web.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public wxpaymentController(IConfiguration configuration) : base(configuration){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,6 +46,9 @@ namespace COMCMS.Web
|
|||||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||||
//services.AddMvc().AddSessionStateTempDataProvider();
|
//services.AddMvc().AddSessionStateTempDataProvider();
|
||||||
|
|
||||||
|
//添加Configuration到静态变量
|
||||||
|
Utils.AddUtils(Configuration);
|
||||||
|
|
||||||
services.Configure<CookiePolicyOptions>(options =>
|
services.Configure<CookiePolicyOptions>(options =>
|
||||||
{
|
{
|
||||||
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
||||||
|
|||||||
Reference in New Issue
Block a user