diff --git a/.gitignore b/.gitignore
index c92bdbb..e66f43b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -304,3 +304,4 @@ __pycache__/
# OpenCover UI analysis results
OpenCover/
COMCMS.Web/wwwroot/userfiles/
+/COMCMS.Web/COMCMS.Web.csproj.DotSettings
diff --git a/COMCMS.Common/Utils.cs b/COMCMS.Common/Utils.cs
index 6d2a31b..4a93e12 100644
--- a/COMCMS.Common/Utils.cs
+++ b/COMCMS.Common/Utils.cs
@@ -22,10 +22,15 @@ namespace COMCMS.Common
static Utils()
{
- //ReloadOnChange = true 当appsettings.json被修改时重新加载
- Configuration = new ConfigurationBuilder()
- .Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true })
- .Build();
+ ////ReloadOnChange = true 当appsettings.json被修改时重新加载
+ //Configuration = new ConfigurationBuilder()
+ //.Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true })
+ //.Build();
+ }
+
+ public static void AddUtils(IConfiguration configuration)
+ {
+ Configuration = configuration;
}
#region 静态变量
diff --git a/COMCMS.Web/COMCMS.Web.csproj b/COMCMS.Web/COMCMS.Web.csproj
index d6087f5..9b95730 100644
--- a/COMCMS.Web/COMCMS.Web.csproj
+++ b/COMCMS.Web/COMCMS.Web.csproj
@@ -283,7 +283,7 @@
Always
- Always
+ Never
diff --git a/COMCMS.Web/Controllers/HomeController.cs b/COMCMS.Web/Controllers/HomeController.cs
index 303f176..1e08291 100644
--- a/COMCMS.Web/Controllers/HomeController.cs
+++ b/COMCMS.Web/Controllers/HomeController.cs
@@ -22,12 +22,14 @@ namespace COMCMS.Web.Controllers
{
public static IConfiguration Configuration { get; set; }
public ConcurrentDictionary AllSession = new ConcurrentDictionary();
- 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()
{
@@ -89,7 +91,7 @@ namespace COMCMS.Web.Controllers
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");
string s = "";
diff --git a/COMCMS.Web/Controllers/wxpaymentController.cs b/COMCMS.Web/Controllers/wxpaymentController.cs
index bf7be8a..0abb1ad 100644
--- a/COMCMS.Web/Controllers/wxpaymentController.cs
+++ b/COMCMS.Web/Controllers/wxpaymentController.cs
@@ -12,6 +12,7 @@ using Senparc.Weixin;
using Senparc.Weixin.MP;
using Senparc.Weixin.TenPay.V3;
using System.Collections;
+using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
namespace COMCMS.Web.Controllers
@@ -124,5 +125,7 @@ namespace COMCMS.Web.Controllers
}
}
#endregion
+
+ public wxpaymentController(IConfiguration configuration) : base(configuration){}
}
}
\ No newline at end of file
diff --git a/COMCMS.Web/Startup.cs b/COMCMS.Web/Startup.cs
index fb670e6..eee4b6b 100644
--- a/COMCMS.Web/Startup.cs
+++ b/COMCMS.Web/Startup.cs
@@ -46,6 +46,9 @@ namespace COMCMS.Web
services.AddSingleton();
//services.AddMvc().AddSessionStateTempDataProvider();
+ //添加Configuration到静态变量
+ Utils.AddUtils(Configuration);
+
services.Configure(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.