मैं किसी उपयोगकर्ता को वेबसाइट के लिए पृष्ठभूमि रंग चुनने और डेटाबेस में चयनित रंग को सहेजने देना चाहता हूं। जब व्यक्ति पृष्ठभूमि में लॉग इन सही रंग प्रदर्शित किया जाएगा।एएसपी.नेट एमवीसी - डायनामिक स्टाइल शीट
निम्नलिखित website के आधार पर, मैं CssHandler.ashx
फ़ाइल के भीतर रंग सेट करने में सक्षम हूं। लेकिन, डेटाबेस से जानकारी प्राप्त करने का सबसे अच्छा तरीका क्या है?
साइट मास्टर पेज,
<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;
}
}
}