I know that there's a way to get Configuration sections by adding it to the services like so:
Configuration.GetSection("SectionName")
And then using dependency injection, I can use that configuration in my controllers. I also know that there's a way to extract connectionstrings from appsettings.json into the startup.cs.
However, what I want is to use a non-connectionstring value from my appsettings.json to be used in my startup.cs. I have a group in my policy that I want to be configurable in the appsettings.json.
In my appsettings.json, there is a config section that looks like this:
"ConfigurableGroupName": "Administrators",
And my policy is being set like the following:
services.AddAuthorization(options =>
{
options.AddPolicy("PolicyName", policy => policy.Requirements.Add(new GroupRequirement("ConfigurableGroupName") ));
});
How do I replace "ConfigurableGroupName" with the value that I have in my appsettings.json? Is there a way to do this or a better way to do this?
EDIT: This is different because I'm trying to use appsettings values that are not connectionstrings in Startup.cs. Not in the controller or anywhere else.