在动态负载asp.net CSS? [英] Load css dynamically in asp.net?

查看:163
本文介绍了在动态负载asp.net CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个内容管理系统,其中用户可以从他们的服务器选择一个CSS文件和应用程序将解析并存储的CSS。应用程序将需要能够解析css类出来,记录它们,并存储到动态添加到另一页的CSS内容,其中用户可以从下拉选择不同的CSS类下来。因此,没有人知道的方式为CSS内容从数据库添加到页面动态,例如?我发现了几个项目解析CSS,这里

I'm creating a content management system where a user can select a css file from their server and the application will parse and store the css. The application will need to be able to parse the css classes out, record them, and store the css content to be dynamically added to another page where a user can select the different css classes from a drop down. So does anyone know of a way to add css content to a page dynamically, for example from a database? I've found a few projects for parsing the css, here .

先谢谢了。

推荐答案

一的WebForms只项目一个好的方法是在你的网页链接到 ashx的处理程序而不是静态的CSS文件:

A good approach for a WebForms-only project is to link to an .ashx handler in your page instead of a static CSS file:

<link rel="stylesheet" type="text/css" href="DynamicStyles.ashx" />

然后创建处理(添加从Visual Studio中的通用处理器项),并在它,你可以从数据库或其他地方加载CSS。只要确保你正确设置内容类型的处理器,从而使浏览器识别响应为有效的样式表:

Then create the handler (add a 'Generic Handler' item from Visual Studio) and within it you can load the CSS from a database or wherever. Just make sure you set the content type correctly in the handler, so that browsers recognise the response as a valid stylesheet:

context.Response.ContentType = "text/css";

这篇关于在动态负载asp.net CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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