While specifing background image urls in css can we get the value from a config entry.
Today my server name is http://imageserver , tomorrow it may change to http://imagecacheserver.
How can i change at one place so that there is no need to change in all the css files.
On the .net side , i get the server url from appsettings.
Are you using .Net MVC? Even if you’re using WebForms you can incorporate MVC (just have a quick Google).
Anyway, if so you could put in a UrlRoute in Global.asax
Then just add an ‘ImageHandler’ controller that does the following:
This will then redirect all HTTP GET requests from /images/* to the dynamic Url. Of course you can then just “jazz-up” the method above to use the Url that you have in your AppSettings rather than the hard-coded string. You may also want to HtmlEncode ‘fileName’ to be safe.
So your CSS code can now just use
background-image: url("/images/blah.jpg")regardless of where the files actually are.