How to handle different web root running in iis on locahost vs. web server (iis7)

asp.netiis7

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 http://www.TheWebsiteName.com (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.

Thanks!

Best Answer

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

127.0.0.1    dev.thewebsitename.com
127.0.0.1    dev.thewebsitename.co.uk
127.0.0.1    dev.anotherwebsitename.com

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 http://uat.thewebsitename.com 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.