mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 17:03:27 +08:00
添加项目文件。
This commit is contained in:
46
CoreCms.Net.Configuration/AppSettingsHelper.cs
Normal file
46
CoreCms.Net.Configuration/AppSettingsHelper.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar.Extensions;
|
||||
|
||||
namespace CoreCms.Net.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// <20><>ȡAppsettings<67><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
/// </summary>
|
||||
public class AppSettingsHelper
|
||||
{
|
||||
static IConfiguration Configuration { get; set; }
|
||||
|
||||
public AppSettingsHelper(string contentPath)
|
||||
{
|
||||
string Path = "appsettings.json";
|
||||
Configuration = new ConfigurationBuilder().SetBasePath(contentPath).Add(new JsonConfigurationSource { Path = Path, Optional = false, ReloadOnChange = true }).Build();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><>װҪ<D7B0><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
/// AppSettingsHelper.GetContent(new string[] { "JwtConfig", "SecretKey" });
|
||||
/// </summary>
|
||||
/// <param name="sections"><3E>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD></param>
|
||||
/// <returns></returns>
|
||||
public static string GetContent(params string[] sections)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (sections.Any())
|
||||
{
|
||||
return Configuration[string.Join(":", sections)];
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user