Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create this type of subdomain on the fly like Blogger.com

Sometime ago I asked this question and I was told that the entry has to be made in DNS etc. I was not sure whether all this is really required or not. The kind of feature that I am looking for is shown in the screenshot below:

enter image description here

As you can see blogger lets the user choose the subdomain for his blog. How can we achieve this? I am basically developing in asp.net C#. How can I allow my users to choose subdomains like this once I have my top level domain. Currently I am developing on localhost.

like image 742
TCM Avatar asked Jul 10 '11 03:07

TCM


People also ask

How do I create a subdomain in Blogger?

Setting Up a Subdomain for BloggerView your domain setting options by clicking the "Custom Domain" option beside Switch To. Blogger initially offers you the option to purchase a domain; click the "Switch to Advanced Settings" link to use your own domain. Fill in your Blogger URL.

What is sub domain in blog?

A subdomain is a prefix added to a domain name to separate a section of your website. Site owners primarily use subdomains to manage extensive sections that require their own content hierarchy, such as online stores, blogs or support platforms. Subdomains function as a separate website from its domain.

How do I create a subdomain wildcard?

In the Subdomain field, place an asterisk * symbol there signifying that you are creating a wildcard subdomain. Choose the domain you want to create a wildcard subdomain for in the Domain section. The Document Root field will automatically generate a path for your wildcard subdomain. You can change the path as needed.


2 Answers

Use a wild card domain in IIS so it traps every request to the top level domain and under.

In asp.net: Create an HttpModule... this will run for every request and you can check the domain name, etc and pull in user information based on the sub-domain. An example httpmodule can be found at URL Rewriting in ASP.NET via HttpModule.

In asp.net mvc: Create a custom RouteHandler (custom based on interface IRouteHandler). Look at RouteHandler vs ControllerFactory question for an example.

like image 159
bbqchickenrobot Avatar answered Sep 18 '22 16:09

bbqchickenrobot


You need to add a wildcard DNS mapping that maps *.example.com to your webserver, and a wildcard hostname mapping telling IIS to send all subdomains to your ASP.Net website.

You can then check Request.Hostname in server-side code and use the appropriate content (or error message)

like image 26
SLaks Avatar answered Sep 16 '22 16:09

SLaks