appsettings.json
{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "option1": "Json", "option2": 2, //物件 "subsection": { "Id": 1, "Name": "Max" }, //陣列 "wizards": [ { "Name": "Gand", "Age": "10" }, { "Name": "Harry", "Age": "17" } ], "AllowedHosts": "*" }
Startup.cs
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)//,ILoggerFactory factory { #region Asp.Net Core讀取組態檔(JSON檔案) { //xml path,不用區分大小寫 WriteLine($"option1 = {this.Configuration["option1"]}"); WriteLine($"option2 = {this.Configuration["option2"]}"); //物件獲取 WriteLine($"subsection_Id = {this.Configuration["subsection:Id"]}"); WriteLine($"subsection_Name = {this.Configuration["subsection:Name"]}"); //陣列獲取 WriteLine("wizards"); WriteLine($"wizardsFirst_Name = {this.Configuration["wizards:0:Name"]}"); WriteLine($"wizardsFirst_Age = {this.Configuration["wizards:0:Age"]}"); WriteLine($"wizardsSecond_Name = {this.Configuration["wizards:1:Name"]}"); WriteLine($"wizardsSecond_Age = {this.Configuration["wizards:1:Age"]}"); } #endregion if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseSession(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/229625.html
標籤:.NET技术
上一篇:初識Core
