I want the user to select the background color for the website and save the selected color in the database. When a person enters the background, the correct color will be displayed.
Based on the following site , I can set the color in the file CssHandler.ashx. But what is the best way to get information from a database?
The main page of the site,
<link href="../../Content/CSSHandler.ashx?file=Site.css" rel="stylesheet" type="text/css" />
site.css
header
{
background-color:#BG_COLOR#;
}
CssHandler.ashx,
public class CssHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/css";
string File = context.Request.QueryString["file"];
string Path = context.Server.MapPath(File);
if (System.IO.Path.GetExtension(Path) != ".css")
context.Response.End();
if (!System.IO.File.Exists(Path))
context.Response.End();
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;
}
}
}
source
share