如何改变与web.config文件中的CSS [英] How to alter CSS with web.config file

查看:308
本文介绍了如何改变与web.config文件中的CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求创建HTML表单,从一个生产环境和开发环境区分视觉对比,使用web.config文件。

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.

我接触到ASP.NET是非常有限的。虽然我一直在研究web.config文件中从昨天开始,由于我缺乏这技术的经验,我仍然不认为我能提供多少信心了坚实的解决方案。

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.

如果这项工作能够直接使用HTML,CSS,PHP或JS来处理,我可以做我自己,但使用的web.config是一个要求。

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.

有已经在发挥CSS样式表,所以我想改变就必须走内联在HTML覆盖的外部样式。

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:

如果这是在生产web.config中:<添加键=CurEnvVALUE =生产/> ,这是在开发中:<添加键=CurEnvVALUE =发展/> ,我怎么能设置窗体的背景颜色的基础上在配置文件中的值

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?

推荐答案

这是我如何做到这一点:

This is how I do it:

有关DEV,例如,我有以下主要我的appSettings

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

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

然后在我的母版页(如果使用Web窗体),或在我的_Layout.cshtml(如果使用MVC),我有以下HTML:

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"]">

有关的WebForms的语法是:

The syntax for WebForms would be:

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

有关生产,我有一个皮肤蓝根据环境在我的appSettings部分,这样设置后,当我部署的应用程序,皮肤会自动更改。

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.

我使用慢真正做到这一点自动,作为构建过程的一部分猎豹

这样,这取决于配置选择,以构建应用程序,使用正确的价值。这是我变换 Web.Production.Config

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>

这篇关于如何改变与web.config文件中的CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆