I would like to let a user select the back ground colour for a website and save the selected colour in a database. When the person logs in the background correct colour will be displayed.
Based on the following website, I am able to set the colour within the CssHandler.ashx. But, I'm not sure the best way to get the information from the database.
Site.Master Page
<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";
// 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;
}
}
}