In WebForms
we would have a web.config
file that we could do ConfigurationManager.AppSettings["SomeKey"];
to retrieve the value from the key-value pair.
I've just started a project in .NET 5.0
and there doesn't seem a simple way to do something that seems to trivial?
I've looked online and have been unsuccessful in following tutorials on how to access these keys in appsettings.json
from a .cshtml
file using @
notation.
appsettings.json:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"MyKey": "wwwwwwwwwww"
}
Index.cshtml:
<h1>
Title - @ConfigurationManager.AppSettings["MyKey"];
</h1>
The above illustrates what I am trying to achieve, is there a simple way to do this rather than creating classes etc as I don't seem to be able to follow their examples.