Change Theme / CSS based on user

前端 未结 8 1843
说谎
说谎 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...

    
    

    style.ashx

    
    

    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.

提交回复
热议问题