I am facing an issue where I have a specific color key in my AppSettings
for the company's brand color, which needs to be applied to a CSS
class. The challenge is how to incorporate this key into my stylesheet
. Is there a way to access the ConfigurationManager
within a .css
file or any alternative method to achieve this?
Web.config
configuration with color keys:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="CorpColorBlue" value="#004B85"/>
<add key="CorpColorGreen" value="#009467"/>
<add key="CorpColorOrange" value="#E98300"/>
</appSettings>
CSS
Class requiring color application (brackets
for clarity):
.thead-company {
color: white;
background-color: [COMPANY-BLUE];
border-color: [COMPANY-BLUE];
}
Currently, I am directly accessing ConfigurationManager
in my views
which leads to redundant code and complications when colors are updated. What alternatives can I explore?
Current approach:
...
@{
var companyBlue = ConfigurationManager.AppSettings["CorpColorBlue"];
}
...
<table class="table table-hover table-bordered table-striped">
<thead class="thead-organization" style="background-color:@companyBlue; border-color:@companyBlue">
...