You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CoreShop/CoreCms.Net.Configuration/AppSettingsHelper.cs

46 lines
1.2 KiB
C#

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 "";
}
}
}