更新获取配置文件
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.0.3" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.4" />
|
||||
<PackageReference Include="MySqlConnector" Version="0.40.3" />
|
||||
<PackageReference Include="NewLife.XCode" Version="9.7.6701.38516" />
|
||||
<PackageReference Include="NewLife.XCode" Version="9.7.6703.38907" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="Senparc.Weixin.MP" Version="14.12.3" />
|
||||
<PackageReference Include="Senparc.Weixin.WxOpen" Version="1.9.1" />
|
||||
@@ -273,4 +273,13 @@
|
||||
<None Include="wwwroot\editor\ckeditor\skins\moono-lisa\readme.md" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="app.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -10,11 +10,20 @@ using COMCMS.Core;
|
||||
using XCode;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration.Json;
|
||||
|
||||
namespace COMCMS.Web.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public static IConfiguration Configuration { get; set; }
|
||||
public HomeController()
|
||||
{
|
||||
Configuration = new ConfigurationBuilder()
|
||||
.Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true })
|
||||
.Build();
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
@@ -32,12 +41,12 @@ namespace COMCMS.Web.Controllers
|
||||
public IActionResult Contact()
|
||||
{
|
||||
ViewData["Message"] = "Your contact page.";
|
||||
Config cfg = Config.FindById(1);
|
||||
ViewBag.siteName = cfg.SiteName;
|
||||
string prekey = Utils.PrefixKey;
|
||||
Article a = Article.FindById(1);
|
||||
ViewBag.siteName = a.Title;
|
||||
|
||||
ViewBag.c = CookiesHelper.GetCookie("abc");
|
||||
ViewBag.d = Utils.GetServerUrl();
|
||||
|
||||
ViewBag.d = prekey;
|
||||
return View();
|
||||
}
|
||||
|
||||
@@ -49,15 +58,48 @@ namespace COMCMS.Web.Controllers
|
||||
#region 测试
|
||||
public IActionResult Test()
|
||||
{
|
||||
JsonTip json = new JsonTip();
|
||||
string strJson = JsonTip.GetJsonString(json);
|
||||
var css = Configuration.GetSection("connectionStrings");
|
||||
var list = css.GetChildren();
|
||||
if(list !=null && list.Count() > 0)
|
||||
{
|
||||
|
||||
//Byte[] bytes = Encoding.UTF8.GetBytes(strJson);
|
||||
//Stream stream = new MemoryStream(bytes);
|
||||
//MyHttpContext.Current.Response.ContentType = "text/plain";
|
||||
//MyHttpContext.Current.Response.Body = stream;
|
||||
}
|
||||
string s = "";
|
||||
foreach (var item in list)
|
||||
{
|
||||
string connName = item.Path.Substring(item.Path.IndexOf(":") + 1);
|
||||
string connectionString = css.GetSection(connName).GetSection("connectionString").Value;
|
||||
string providerName = css.GetSection(connName).GetSection("providerName").Value;
|
||||
s += item.Path.Substring(item.Path.IndexOf(":")+1)+ "|"+ Configuration.GetSection(item.Path+ ":connectionString").Value+"|" + Configuration.GetSection(item.Path + ":providerName").Value +"|"+connectionString+"|"+ providerName +"|||" + list.Count();
|
||||
}
|
||||
|
||||
return Content("ok");
|
||||
return Content(s);
|
||||
}
|
||||
|
||||
public IActionResult Test2()
|
||||
{
|
||||
var settings = "appsettings.json".GetFullPath();
|
||||
var css2 = new ConfigurationBuilder().AddJsonFile(settings).Build().GetSection("connectionStrings");
|
||||
|
||||
string s = "";
|
||||
if (css2 != null)
|
||||
{
|
||||
foreach (var item in css2.GetChildren())
|
||||
{
|
||||
var name = item.Path.Substring(item.Path.IndexOf(":") + 1);// item["name"];
|
||||
var constr = item["connectionString"];
|
||||
var provider = item["providerName"];
|
||||
s += $"{name}|{constr}|{provider}|||";
|
||||
//var type = DbFactory.GetProviderType(constr, provider);
|
||||
//if (type == null) XTrace.WriteLine("无法识别{0}的提供者{1}!", name, provider);
|
||||
|
||||
//cs.Add(name, constr);
|
||||
//_connTypes.Add(name, type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Content(s);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -8,6 +8,17 @@
|
||||
"SystemSetting": {
|
||||
"FileAllowedExtensions": "zip,rar,7z,doc,docx,xls,xlsx,ppt,pptx,csv,pdf,txt,gz,gzip,gif,png,jpg,jpeg,bmp,avi,fla,flv,swf,mp4,mp3,mov,mid,mpg,mpeg,rm,rmvb,wma,wav,wmv",
|
||||
"ImageAllowedExtensions": "gif,png,jpg,jpeg,bmp",
|
||||
"MediaAllowedExtensions": "flv,mp4,mp3,wmv,swf,mov"
|
||||
"MediaAllowedExtensions": "flv,mp4,mp3,wmv,swf,mov",
|
||||
"COMCMSPrefixKey": "abc_"
|
||||
},
|
||||
"connectionStrings": {
|
||||
"dbconn": {
|
||||
"connectionString": "Server=.;Port=3306;Database=comcmscore;Uid=root;Pwd=root;",
|
||||
"providerName": "MySql.Data.MySqlClient"
|
||||
},
|
||||
"mssqlconnon": {
|
||||
"connectionString": "server=(local);database=comcmscore;uid=sa;pwd=123456",
|
||||
"providerName": "System.Data.SqlClient"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user