Hi @Keerthi Mettu ,
I wrote a demo, you can refer to it and you can read the value.
I first added the test attribute in appsetings.json.
"MySettings": {
"DbConnection": "abc",
"Email": "abc@domain.com",
"SMTPPort": "5605"
}
Now, in our ConfigController, we will add a private field of type “IConfiguration” which is found in Microsoft.Extensions.
public class ConfigController : Controller
{
private IConfiguration configuration;
public ConfigController(IConfiguration iConfig)
{
configuration = iConfig;
}
public IActionResult Index()
{
string dbConn = configuration.GetSection("MySettings").GetSection("DbConnection").Value;
return View();
}
Rseult:
Choose the corresponding field for any attribute you need, or you can define a model to get it all at once.
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
ChaoDeng