Changing CSS file dynamically
I have a webdev problem
I have close to 10,000 serverside pages, all of thse use the same stylesheet. I have created a new serverside page which is like a dyn开发者_运维百科amic menu system to help find specific pages from the existing 10,000 pages quickly and easily.
The problem is, that if the serverside pages are accessed the old way using the old menu system, they should retain their old stylesheet. however, if they are accessed via the new menu system, they should use a new refreshed stylesheet.
Editing 10,000'ish pages does not seem like a good option. What is the best way to go about tackling this problem?
Have the stylesheet in an app_themes folder and set this in the web.config. Then you can change between the two quickly. Or you could set this in code in the pre_init event
EDIT: 1: Add and app_themes folder, create two sub folders with theme names (eg, default or Blue etc)
2: either in the web.config set the or
3: catch the page_init for each page that you wish to change(or for master pages and lots of pages have a base page class and override page_init) and set the Page.Theme = to a theme you want. Best off saving this in Session State from what I can tell. So something like this:
if (Session["Theme"] == null)
{
//the string is the theme as per the cleaners default
string chosenTheme = selectedTheme();
Session.Add("Theme", chosenTheme);
Page.Theme = ((string)Session["Theme"]);
}
//if the page is reloaded.
else
{
Page.Theme = ((string)Session["Theme"]);
}
Hope this helps sire
If you can't write some global server side code nor have a global template for all the 10.000 pages, my first idea is to have a URL-Rewrite for the CSS file based on a specific url parameter. So you could have a 2nd CSS file which will be served if this parameter is submitted, if not the rewrite would serve the original css file.
Normally Id have suggested a URL rewrite, so that requests for the old styles are redirected to new. (IIS can do this, as an example : http://www.iis.net/download/URLRewrite )
The following page might be useful to you Oshirowanen.
http://blogs.msdn.com/b/dotnetinterop/archive/2008/06/18/rewriting-urls-on-iis5-iis6-or-iis7-mod-rewrite-on-iis.aspx
I googled around for mod_rewrite style options for iis6 and this cropped up. It's from 2008 but seems to be at least around what you're looking for in the context of iis6 and would, I would hope, allow you to set up some kind of access rule that could possibly redirect clients on one of the domains to some new css folder/assets you specify.
精彩评论