Link to home
Start Free TrialLog in
Avatar of peupy
peupy

asked on

How can we create a Subdomain using ASP?

I am looking forward for some help to create a subdomain using classic ASP.
for eg. I have a domain named http://www.mydomain.com and want to create a subdomain that would show like http://subdomain.mydomain.com

Thanks
Avatar of geir_andersen
geir_andersen
Flag of Norway image

this is done on DNS level.
you can ask you domain-registrar to create such a sub-domain.

-Geir
Avatar of peupy
peupy

ASKER

Hello Geir,
           Can't the subdoamin be created by coding in ASP?

-Peupy
No, I'm afraid not.

more info:

Say you have the domain: somedomain.com registrered via some registrar.
That registrar also controls the NameServers (DNS) for this domain..

You could do the following:
If you control your own web-server, you can ask the registrar to point the A record of the sub-domain wanted, to the IP address of your server. (NOTE! your server needs to be configured to answer requests on said domain.)

If your website is hosted on your registrar's server, you can create a folder on the same level as your normal web-site, you can ask them to point the A record to that folder

-Geir
Avatar of Alexandre Simões
Why don't you just use it as:
http://www.mydomain.com/subdomain

It's not quite what you want but it would be pretty much easyer and cheaper... :)

Alex :p
ASKER CERTIFIED SOLUTION
Avatar of JohnBPrice
JohnBPrice

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peupy

ASKER

Hello John,
              I would like some help from you regarding the implmentation of this feature. It would be nice if you could help me with the steps to achieve it.

Thank you :)
1) See if you already have a "*" DNS record for your domain, some ISP's will create it for you.  Go to whatever.mydomain.com and see if you get to your site, or at least get a 404 error.  (you could also try ping or nslookup, you may not get a response, but if it finds the IP address, you are good).

2) If you don't get an IP address for whatever.mydomain.com, you need to create a "*" record.  You need to know who has the name server for your domain.  If it is a hosting service, the hosting service probably has the names.  They will either allow you to add the DNS record yourself through your administration page, or you can ask their support to create it for you.

3) Once you get the "*" record working, the rest is easy.  In your default home page, probably default.asp, put in code like the following.  This is assuming you have predefined subdomain names.  If you want to dynamically create subdomains, you just need to create a mechanism to decide what home page each domain should go to.  You could store the subdomain and corresponding home page in a database, or you could parse out the subdomain name and use that as a home page name, or maybe your subdomain name specifies a user, in which case you'd store it in a session variable and you later pages could reference it.

<HTML>
<HEAD>
<TITLE></TITLE>
<%
sname = Request.ServerVariables("SERVER_NAME")
sname = ucase(sname)
if InStr(sname,"subdomain1") <> 0 then
      response.redirect "/SubDomain1/default.htm"
elseif InStr(sname,"Subdomain2") <> 0 then
      response.redirect "/SubDomain1/default.htm"
elseif InStr(sname,"Subdomain3") <> 0 then
      response.redirect "/SubDomain3/default.htm"
elseif InStr(sname,"Subdomain2") <> 0 then
      response.redirect "/SubDomain3/default.htm"
end if
%>
</HEAD>
<BODY>

<P>Thank you for your interest in DataBanque.&nbsp; Please
select the division you are interested in</P>
<P><A href="http://www.databanque.com">DataBanque Building Product Manufacturer
Services</A></P>
<P><A href="/DBResearch">DataBanque Research</A></P>

</BODY>
</HTML>
Avatar of peupy

ASKER

Hello John,
               Thanks a lot :)

Regards
Peupy
Sure, BTW, I just noticed a bug in the code above.  I did a UCASE, so testing for the subdomains should be in caps, e.g. if InStr(sname,"SUBDOMAIN1") <> 0 then

Also I used subdomain2 and subdomain3 twice, oops.