我想让用户选择网站的背景颜色并将所选颜色保存在数据库中。当此人登录背景时,将显示正确的颜色。
基于以下网站,我可以在CssHandler.ashx
文件中设置颜色。但是,从数据库中获取信息的最佳方式是什么?
网站母版页,
<link href="../../Content/CSSHandler.ashx?file=Site.css" rel="stylesheet" type="text/css" />
网站.css,
header
{
background-color:#BG_COLOR#;
}
CssHandler.ashx,
public class CssHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/css";
// Get the file from the query stirng
string File = context.Request.QueryString["file"];
// Find the actual path
string Path = context.Server.MapPath(File);
// Limit to only css files
if (System.IO.Path.GetExtension(Path) != ".css")
context.Response.End();
// Make sure file exists
if (!System.IO.File.Exists(Path))
context.Response.End();
// Open the file, read the contents and replace the variables
using (System.IO.StreamReader css = new System.IO.StreamReader(Path))
{
string CSS = css.ReadToEnd();
CSS = CSS.Replace("#BG_COLOR#","Blue");
context.Response.Write(CSS);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}