Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have several websites that I help manage. When running on my local machine (under iis7), the websites run on under a folder on my machine d:\WebRoot\TheWebsiteName and run as htt://localhost/TheWebsiteName, but when they are deployed they run as (also running under iis7)

Currently I am handling the path to the website resources (images, javascript, etc) via code. But I was wondering if there was a better way to handle this rather than writing specialized code in the website.


share|improve this question
I'm not sure if this question would be better at or at – FrustratedWithFormsDesigner May 15 '12 at 17:41

For each of the websites setup a hostname in C:\Windows\System32\drivers\etc\hosts as a loopback to your local machine:

this way you won't have to do any special mapping for your website resources. You can then setup multiple websites in IIS7 as you would do on your live webserver that only serve for the specified urls above. All you then need to do is change your web project's start url to be the new dev address and it will all be working.

I always then setup the different test servers exactly the same so all you need to do is change the subdomain to etc. If you have a lot of sites you can also created a page with links to all the different sites and then have that bookmarked.

Also if you have a CDN for images you can either add that url as a loopback too, or just upload the images when developing. If you have them locally the speed will be great but you will need to make sure that you remove that loopback when you test.

This always worked like a dream for me and because it replicates your live servers and things like incorrect image/script urls will show up when developing. It does take a little more time to setup but is worthwhile and if you script it using PowerShell it won't be painful if you have to set it up again or for another developer.

share|improve this answer
I really like this idea Caveman! – O.D. May 15 '12 at 18:27
Thanks, hope it works well for you! :) – caveman_dick May 16 '12 at 8:56
+1 but I'd recommend thewebsite.local (otherwise your aliases may interfere with actual subdomains) – danlefree May 16 '12 at 21:43
@danlefree That's all very well if the OP's guys aren't using .local for the internal AD domain. If you use a subdomain and you run the website you should really know if that subdomain is used or not! :) In fact I used to use something that didn't look like a domain name at all lm-haysgb-ip00 (don't do much webdev now! :( ). – caveman_dick May 17 '12 at 8:55
Ok a workmate has just tweeted about which is a really great idea and means no modification of the hosts file is required. – caveman_dick Jun 27 '12 at 9:42

Presuming the resources are local, you should not need any special code at all -- just use relative paths to your resources and it will work in any environment. IE, use:

<script src = "scripts/whatever.js"></script>

Don't use something like:

<script src = "http://mylocalmachinename/scripts/whatever.js"></script>

If you are doing some CDN-like thing with a separate images domain then you will need some code somewhere.

share|improve this answer
We do use a separate Cdn server for images, and it does help with some of of this. And also a CMS for the website content, the CMS returns the path as htt://localhost/TheWebsiteName – O.D. May 15 '12 at 18:25
The CMS should be adjusting itself to the environment then . . . – Wyatt Barnett May 15 '12 at 18:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.