Using C# to dynamically generate CSS files

前端 未结 4 789
暖寄归人
暖寄归人 2021-01-05 10:07

I have a site that gets deployed to over a dozen clients. The main website has a base template, and each client has a client folder that overrides the colours. The problem i

4条回答
  •  心在旅途
    2021-01-05 10:45

    Instead of a Web Control, you're likely better off creating a Generic Handler. This won't have the overhead that a web control has.

    1. In your handler, accept the clientID via querystring - this allows you to cache on a client level
    2. In your .master file, you can link to it < link src="MyCssHandler.ashx?ClientID=<%=ClientID%>" >

    In your handler you have a few ways to work with the CSS.

    1. Just have a bunch of response.write for the css, and put in relevant client values
    2. Create an external CSS file with it's own special identifier - maybe <% %>. You could then load all the client specific values in a NameValuePair Collection, and then loop through the external CSS file, parsing <% NAME %> and replacing with the correct value. Then response.write this file. More complicated true but it allows for a hell of a lot cleaner CSS files

提交回复
热议问题