Set CSS base Urls in web.config

Nov 9, 2011 at 7:51 PM

Hello,

I was wondering if there is currently a way to set a base url in the web.config that can automatically be appended to url's encountered in CSS.

Let me explain my situation first.  We are in the process of moving our images to a CDN but for development we want developers to hit the local content folder.  So in VS2010 I would like to be able to specify in the Web.Release.config the path to the main folder on our CDN for images and in the web.config used by developers we would have the path to "content/images" to grab them locally.

Is there a way to do this without building the whole Combres project locally and putting my changes into FixUrlsInCssFilter.  I tried just copying the code for that filter into a local class but it's using internal methods in Combres.  

Anybody have any suggestions or ideas on how to accomplish this type of thing?

 

Thanks!

Jeff

Nov 10, 2011 at 4:45 PM

Ok, I figured there is no current way to achieve this so I am going to build the project locally and modify the FixUrlsInCssFilter to read a setting from the web.config.  The issue I'm running into is that I've simply pulled the source code for the latest release (2.2.1.2) and I can build it on my machine but when I put the reference to that dll in my project then HttpContext.Current is null in Configuration.GetCombresUrl (I receive "Object Reference Not Set to an Instance of an Object" when I run it). 

It looks like this is called through the PreApplicationStartMethod which I'm not very familiar with.  Does anyone have any suggestions as to why this works for the dll I have from CodePlex but it fails when I try to build it myself?

Thanks again,
Jeff

Nov 10, 2011 at 6:35 PM

There's no reason to build your own version of combres for this; just create your own filter implementation in your project and reference it in your combres config.

See my responses to this question for further guidance: http://stackoverflow.com/questions/7842060/combres-not-fixing-relative-urls-despite-the-filter

Nov 10, 2011 at 9:54 PM

Great, thank you.  Initially I looked at modifying what was already there and couldn't get the existing code in FixUrlsInCssFilter.cs to work because of the internals it was accessing in Combres, I didn't even give it a thought to start from scratch on it.

Thanks again!