使用C#动态生成CSS文件 [英] Using C# to dynamically generate CSS files

查看:448
本文介绍了使用C#动态生成CSS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被十多个客户部署到网站。主要网站有一个基本模板,并且每个客户端有覆盖颜色的客户端文件夹。问题是,有很多的CSS文件,因此使得它迫使我们必须更新每个客户端的改变需要较长的时间。自动构建过程需要替换更新的文件的照顾。

I have a site that gets deployed to over a dozen clients. The main website has a base template, and each client has a client folder that overrides the colours. The problem is that there are a lot of CSS files, so making a change that forces us to update every client takes a long time. The automated build process takes care of replacing the updated files.

我想改变CSS文件是不是用户控件,然后将这些用户控件可以从那里客户特定的值存储在另一个用户控件继承。

I would like to change the CSS files to be usercontrols instead, and those usercontrols could then inherit from another usercontrol where client specific values are stored.

因此​​,而不是有一个forms.css文件,然后一个/client/forms.css文件,我将不得不从包含颜色的用户控件继承Forms.ascx文件。

So instead of having a forms.css file and then a /client/forms.css file I would have a Forms.ascx file that inherits from a usercontrol that contains the colours.

例如:

<%@ Control Language="C#" ClassName="Forms" %>
<%@ Register TagPrefix="css" TagName="Client" Src="~/css/ClientStyling.ascx" %>

/* CSS Document */
body
{
  color:<%=Client.BodyColor%>
}

然后母版将从用户控件继承来代替。这将使得在客户端站点的更容易的维护。

Then the masterpage would inherit from the usercontrol instead. This would make the maintenance of the client sites much easier.

那么,这个解决方案高效和建议?还是有更好的方式来完成相同的结果呢?

So is this solution efficient and recommended? Or is there a better way to accomplish the same end result?

如果这是可能的话,也有可能有Forms.ascx控制输出标记为CSS?或使扩展.css和仍然有ASCX属性呢?

If this is possible, would it also be possible to have the Forms.ascx control output the markup as CSS? Or make the extension .css and still have the ascx properties?

推荐答案

而不是一个网络控制的,你可能最好创建一个通用处理器。这不会有开销的Web控件。

Instead of a Web Control, you're likely better off creating a Generic Handler. This won't have the overhead that a web control has.


  1. 在您的处理程序,接受通过查询字符串ClientID的 - 这允许你缓存在客户端级别

  2. 在您的.master文件中,可以链接到它&LT;链接SRC =MyCssHandler.ashx客户端ID =&LT;%=客户端ID%>>

在你处理你有几个方面的CSS工作。

In your handler you have a few ways to work with the CSS.


  1. 只要有对CSS一堆的Response.Write,并把相关客户价值

  2. 创建与它自己的特殊标识外部CSS文件 - 也许与LT;%%>。然后,您可以通过外部CSS文件加载所有的客户特定的值在的NameValuePair集合,然后循环,解析&LT;%NAME%>,并用正确的值替换。然后RESPONSE.WRITE此文件。更复杂真实的,但它允许很多的地狱清洁CSS文件

这篇关于使用C#动态生成CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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