tags:

views:

297

answers:

8

I've been tasked with putting a mechanism in place to change the css colours in a .Net site dynamically. The purpose is to ensure that when our internal application sites are built and deployed to our UAT servers that the UI of the site is identifiably different from the live versions without changing the code base.

One option is to go through each site and create a parallel UAT version of the CSS but I would like to have a handler or something in place to replace colour defintions in the CSS based on a key / value pair as our colours are pretty standard across the apps. Ideally it should simply intercept the css request, replace any standard colour code definitions with the required UAT colours and server the CSS out with the replacements. Does this sound like a realistic solution to the problem or can anyone suggest a better approach which doesn't involve managing multiple css definitions?

A: 

Just an update, I've found something very similiar to what I'm trying to achieve here.

http://pastebin.ca/1205892

A: 

Ok, nearly there but how do I get an HTTPHandler intercept css files? It seems to only be responding to aspx page requests and ignoring the css requests. Can this be done without tweaking around on the web server ISAPI filters?

A: 

Alex (the guy you posted the blog link to) says you need to add the following to the web.config:

If you are using "IIS6 / Visual studio test server":

<system.web>
    <httpHandlers>
        <add verb="*" path="*.css" type="StyleSheetHandler"/>
    </httpHandlers>
</system.web>

If you are using IIS7:

It should work, however if it doesn't then you will need to check the mappings like so:

For a website:

IIS6 > Website > Home directory

For a virtual directory browse to:

IIS6 > Virtual folder > Virtual directory (default tab)

Click the configuratino button in the application settings area.

Locate the .css extension and check that it is using the aspnet_isapi.dll

If it is not then simply change it so that it is. (You can copy the full URL from any other .NET extension, .aspx for example)

Then everything should work fine.

John_
A: 

Tried that but the http handler still did not register the requests for *.css files. Managed to put a 'hack' in place to rename the default.css to default.css.aspx and then within the handler determine whether it's a css file we're dealing with.

The projects that I'm working with are 1.1 web apps. Could that be the reason I'm having issues? I followed Alex's steps and tried placing the ISAPI .css relationship against both the 1.1 and 2.0 ASP_ISAPI dlls.

A: 

Was thinking I could put a primary HTTP Handler in place, regular expression match any .CSS references within the .ASPX files and change the references to .CSS.ASPX on the fly so that they are then caught in the CSS HTTP Handler.

How do I dynamically change the CSS Href in the aspx pages within the handler?

A: 

You need something as complicated as HTTP handlers. Just create an .aspx page which outputs CSS. It can be a .aspx and just have your tag refer to the .aspx page.

If you really want to have your .css pages handled by ASP.NET (I wouldn't because it affects performance), then you want to add an extension mapping like this: http://blogs.iis.net/ruslany/archive/2008/09/30/wildcard-script-mapping-and-iis-7-integrated-pipeline.aspx

ajma
A: 

Regarding intercepting CSS requests, you need to configure IIS to tell it what to do with CSS requests ...

  1. In the properties of your website, create an Application if you do not already have one.

  2. Click "Configuration"

  3. Open up the ASPX application mapping

  4. Copy the executable path to the clipboard

  5. Close that application mapping without making any changes

  6. Add a new application mapping pointing to the same executable path as the ASPX one for CSS files

You should find that CSS requests will get through to your HttpHandler now.

Antony Scott
A: 

You may also want to take a look at less:

http://www.4guysfromrolla.com/articles/030310-1.aspx

fordareh