How to alter CSS with web.config file

百般思念 提交于 2020-01-06 02:46:06

问题


I have been asked to create a visual contrast for an HTML form to distinguish it from a production environment and a development environment, using a web.config file.

My exposure to ASP.NET is very limited. Although I've been researching web.config files since yesterday, due to my lack of experience in this technology, I still don't think I can provide a solid solution with much confidence.

If this job could be handled directly with HTML, CSS, PHP or JS I could do it myself, but using web.config is a requirement.

The goal is to create an unmistakable visual change (let's say, lightgreen background) when a user is on the development form.

There is already a CSS stylesheet in play, so I'm thinking the change would have to go inline in the HTML to override the external styles.

So here's the question, if it makes any sense:

If this is in the production web.config: <add key="CurEnv" value="Production"/> and this is in dev: <add key="CurEnv" value="Development"/>, how can I set the form's background color based on the value in the config file?


回答1:


This is how I do it:

For DEV, for example, I have the following key in my appSettings:

<appSettings>
    <add key="skin" value="skin-gray"/>
    ...
</appSettings>

And then in my Master page (if using Web Forms) or on my _Layout.cshtml (if using MVC), I have the following HTML:

<body class="@System.Configuration.ConfigurationManager.AppSettings["skin"]">

The syntax for WebForms would be:

<body class="<%=System.Configuration.ConfigurationManager.AppSettings["skin"]%>">

For Production, I have a "skin-blue" setting in my appSettings section and that way, when I deploy the app, depending on the environment, the skin is automatically changed.

I actually do this automatically, as part of the Build process using Slow Cheetah

So that depending on which Configuration is chosen to build the application, the right value is used. This is my transform for Web.Production.Config:

<appSettings>
    <add key="skin" value="skin-blue" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
  </appSettings>



回答2:


I think you can read those link. It's may help you:

http://forums.asp.net/t/1349824.aspx?How+to+set+CSS+color+settings+from+web+config

Dynamically setting CSS values using ASP.NET



来源:https://stackoverflow.com/questions/32127776/how-to-alter-css-with-web-config-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!