Change Theme / CSS based on user

前端 未结 8 1845
说谎
说谎 2021-01-02 06:10

I am building a product that we are eventually going to white-label. Right now I am trying to figure out the best way to facilitate these requirements programmatically so th

相关标签:
8条回答
  • 2021-01-02 06:58

    I like the idea of using dynamic CSS using an ASP.Net Handler...

    <link rel="stylesheet" href="style.ashx" />
    

    style.ashx

    <!--WebHandler Language="C#" Class="StyleSheetHandler"-->
    

    StyleSheetHandler.cs

    public class StyleSheetHandler : IHttpHandler {
            public void ProcessRequest (HttpContext context)
            {   
                context.Response.ContentType = "text/css";
                context.Response.ContentEncoding = System.Text.Encoding.UTF8;
    
                string css = BuildCSSString(); //not showing this function
    
                context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(600));
                context.Response.Cache.SetCacheability(HttpCacheability.Public);
                context.Response.Write( css );
            }
    
            public bool IsReusable
            {
                get { return true; }
            }
    
    }
    

    The BuildCSSString() Function will build the css based on the values stored in the database and return it to override the base style on the master page.

    0 讨论(0)
  • 2021-01-02 06:59

    I would avoid using the !important clause and instead just ensure their values appear in a <style> tag following the import of the regular style sheets.

    Otherwise, I would do it the same way.

    0 讨论(0)
提交回复
热议问题