开发者

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

开发者 https://www.devze.com 2023-03-18 08:26 出处:网络
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 show

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:

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

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 开发者_JS百科can I allow my users to choose subdomains like this once I have my top level domain. Currently I am developing on localhost.


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.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消