views:

58

answers:

3

Hi,

I would like to know the method of setting up sub-domains in the development environment. Don't have any hosting account yet. But would like to test it up internally by simulating a similar setup that would be provided by the hosting company later on.

Thanks!

+2  A: 

Open the C:\Windows\System32\Drivers\etc\hosts file in Notepad (make sure you run Notepad as an Administrator) and add a bunch of entries like this:

127.0.0.1 test1.local 
127.0.0.1 test2.local 
127.0.0.1 test3.local

Save the file and load up your application using each test domain e.g. http://test1.local/ (or if you're using the VS development server, include the port number). You can use any names you want if you don't like my style :)

John Sheehan
Thanks! But how do I map these subdomains to the folders in my application?
If you want to convert those into example.com/test1, etc. you'll need to use URL rewriting. If you're using subdomains though, why map them? Just serve up the content from that URL.
John Sheehan
Ok. Looks like it will not be possible to achieve this using .net's inbuilt server. Will try setting it up in IIS and confirm if it works. Thanks
Sorry John. Saw your reply only after I posted mine.Yes. URL rewriting is not what I want. I would like to serve the content from the subdomain URL itself. But that subdomain URL should know where to look for info. Right? I believe that is where the settings in IIS come into picture. Please correct me if I am wrong. Thanks
You would configure that in IIS. Create a couple sites, set the Host Header bindings to the test domain for each site, then point it at the folder you want for that subdomain
John Sheehan
Thanks John. Was able to do that. Now am able to access the folders in my .net app using subdomain urls. But I am facing a problem here. At a time, am able to access only one website. Not able to boot both the websites at the same time. So, if I want my main site to call the subdomain, (and keep the session variables active) how do I go about it? Thanks!
There's too much to discuss in this comment box, I would ask a new question on how to handle cookies/sessions with this setup. Be sure to describe what you're trying to accomplish in more detail. If you describe your problem instead of your solution, you may get better answers here.
John Sheehan
Ok Then. Thanks. Posted a new question.
+3  A: 

Edit (with a notepad) the hosts file that is existing on

c:\WINDOWS\system32\drivers\etc\

to enter your test sites something like this

127.0.0.1 local.mysite.com
127.0.0.1 sub1.mysite.com
127.0.0.1 sub2.mysite.com
Aristos
Why -1 ? John have type the address error in the first place ! and just was a little faster than me. And test1.local is not a site !
Aristos
instead of copying the answer, why didn't you point out the error in mine? test1.local sure can be a site. it's a valid DNS name just like any other and you'll never confuse it for a production site or cause a name conflict with a real domain.
John Sheehan
@John I was not copying your ! we just send it at the same time with few seconds different, then I see that you have a little diferent answer and I just left mine too.
Aristos
A: 

If you're using IIS on your development server to replicate your hosting company's conditions, be sure and set up Host Headers too.

http://technet.microsoft.com/en-us/library/cc753195%28WS.10%29.aspx

Damien Dennehy