How to add section in appsettings.json
See original GitHub issueI want to add some configurations to appsettings.json, and I need to read it in project xxx.ApplicationService and project xxx.Core.
var configuration = AppConfigurations.Get(Web.WebContentDirectoryFinder.CalculateContentRootFolder()); Logger.Info(configuration.GetConnectionString("Default")); Logger.Info(configuration.GetSection("SmsSettingNames:AliyunSms:ServiceUrl").Value);
I can get the connection string, but section is null.
appsettings.json
{ "ConnectionStrings": { "Default": "Data Source=(LocalDB)\\ProjectsV13;Initial Catalog=AbpZeroTemplate; Integrated Security=True" }, "SmsSettingNames": { "AliyunSms": { "ServiceUrl": "dysmsapi.aliyuncs.com", "AppKey": "XXXXXXXX", "AppSecret": "XXXXXXX", "DefaultFreeSignName": "XX", "DefaultSmsTemplateCode": "SMS_XXXX" } }
What should I do
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
@rqx110 we don’t ASP.NET does, it is copied to bin folder when you run the app.
@LGinC you can try like this;
Define an interface in your Core project like below;
Then create it’s implementation in your Web project like this;
After all, try injecting IAppConfigurationAccessor and access the config.
@rqx110 检查了,保存了,重启了,没用啊