Monday, August 24, 2009

Resolve your

There are times when you want to do something with the URL, or portions of the URL by parsing it. However, if you are on your local box, you are only going to see the good old AKA "localhost" in your URL. Lets say you want to parse http://msdn/testapplication so as to get only the 'msdn' part of the URL. You wont be able to do it on your local box because IIS would resolve your hostname to localhost.

Here's what you can do to mask a real-time url over your localhost.
From your file explorer, locate the etc folder under:


Here, you can see a file named hosts, of type file. Open it with a word editor program (notepad), and you will see the mappings of IP addresses to host names. You will by default, see an entry for resolved/mapped to localhost. All you need to do is change the name from localhost to whatever name (msdn, in our example). Now, when you type http://msdn/testapplication, you will actually be firing up your local web application. Now, you can do whatever you wish to do with the url since it is not "localhost" anymore, linguistically speaking.

I hope that was a cool trick that comes in handy! Until next time...

No comments: