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 and want to create a subdomain that would show like

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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

geir_andersenSystems engineerCommented:
No, I'm afraid not.

more info:

Say you have the domain: 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

Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Alexandre SimõesManager / Solutions ArchitectCommented:
Why don't you just use it as:

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

Alex :p
While it's true that to create a real subdomain, you need to modify your DNS records, you can none the less make it look like a subdomain under the right circumstances.

2nd level domains, such as "" will have a DNS record with a "www" prefix, thus specifying the IP address for "".  If you also have a DNS record with a "*" prefix, it will cover anything not explicitly named, e.g. will go to the address specified in the DSN record with the "*" prefix.  You can then test what the URL is in code using Request.ServerVariables("SERVER_NAME")

try this or

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peupyAuthor Commented:
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 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, 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.

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

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

peupyAuthor Commented:
Hello John,
               Thanks a lot :)

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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.