Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test subdomains on a development machine? abc.localhost

I am trying to develop an asp.net site with multiple subdomains. I am new to web sites in general, and asp.net in particular. However, it seems that wildcard subdomains are properly setup with a combination of dns entries and web server configuration - which isn't going to happen on my development machine. Therefore I'm manually inserting entries in my windows hosts file:

127.0.0.1  localhost
127.0.0.1  abc.localhost
127.0.0.1  xyz.localhost

However, when I try to interrogate the Request.Url property there is no subdomain to be seen. For example, if I hit http://abc.localhost:1660/ in the browser I get http://localhost:1660/ from Request.Uri.ToString(); the abc is just gone?!

I don't know why the hosts file works like this, but is there any other method I can use to get subdomains into my local web application? Thank you all.

Note that I'm only using the built-in asp.net development server rather than a full iis server. (I can't get access to a full IIS this weekend, but I would still like to know if that would help.)

like image 486
Josh Avatar asked May 16 '09 17:05

Josh


People also ask

Can you have subdomains on localhost?

localhost is not supposed to have any subdomains. To do so violates the approved RFC standards. localhost has an A record and in IPv6 environments, an AAAA record. All other DNS record types, including SOA are forbidden.

How do I access my subdomains?

Accessing the Subdomain MenuLog in to your Just Host cPanel account. Click the Domains tab at the top of your account. Click On Subdomains on the submenu.

How do I know if I have a subdomain?

A subdomain contains a second name before the SLD. For instance, if the Themeisle blog was hosted on https://blog.themeisle.com , the blog would be the subdomain.


1 Answers

Don't know about the headers, but one little-known trick that I've used is that all of the 127.* addresses are localhost addresses, not just 127.0.0.1. You can actually run one server listening on 127.0.0.1 port 80, and another webserver instance listening on 127.0.0.2 port 80. So then you'd name 127.0.0.1 localhost, 127.0.0.2 could be abc.localhost (or abc.mydomain.com so you can test the real live URLs against your local webserver), etc.

like image 161
Joe White Avatar answered Oct 12 '22 11:10

Joe White