"CommonConfig": {
"Settings": [
{
"Key": "UniqueKey", "UniqueKey" will be use to get the logo link/directory
"Value": "~/Favicon" "Faviconlink" actual logo link/directory
}
]
}
Create helper class.
Copied successfully!
public class CommonConfig
{
public CommonConfig()
{
}
public List Settings { get; set; }
This function will be use to get the link from appseetings.json "CommonConfig"
public string GetValue(string key)
{
return Settings != null ? Settings.Where(s => s.Key == key).Select(s => s.Value).FirstOrDefault() : null;
}
public class Setting
{
public Setting()
{
}
public string Key { get; set; }
public string Value { get; set; }
}
}
Add this line to Startup.cs ConfigureServices function.
Copied successfully!
This will inject the CommonConfig settings to our "Helper class"
services.Configure(Configuration.GetSection("CommonConfig"));
Usage
Inject CommonConfig to view.
Copied successfully!
This inject's the CommonConfig on our view
@inject IOptions<PelicanCorp.PCUI.MVCCore.Helper.PCUI.CommonConfig> CommonConfig
Call logo.
Copied successfully!
Get link by using the "UniqueKey"
<img asp-append-version="true" src="@Url.Content(CommonConfig.Value.GetValue("UniqueKey"))"/>