0

My blog creates URLs like this:

http://localhost:55649/Blogs/MyBlog

How can I create a sub domain so that it looks like it's hosted on it's own subdomain, like this:

http://myBlog.localhost:55649/

I know I can create a sub domain to redirect to localhost:55649/Blogs/MyBlog, but I want that to be the actual domain. Is this possible?

user1477388
  • 20,790
  • 32
  • 144
  • 264
  • possible duplicate of [Is it possible to make an ASP.NET MVC route based on a subdomain?](http://stackoverflow.com/questions/278668/is-it-possible-to-make-an-asp-net-mvc-route-based-on-a-subdomain) – Tommy Jul 27 '12 at 00:33

2 Answers2

1

Probably it is not possible by ASP.NET MVC own possibilities like routing. You need to create two sites in IIS (one for domain and another for subdomain) pointed to the same directory with site code.

And surely it is not possible with ASP.NET Development Server.

Probably URL Rewrite module would also help you: http://www.iis.net/download/urlrewrite

STO
  • 10,390
  • 8
  • 32
  • 32
  • Isn't it possible to get the Host variable (http://myBlog.localhost) and then make that the default controller or something? – user1477388 Jul 26 '12 at 19:44
  • It is not possible in straight way, because routes are set up in Global.asax Application_Start method where request context is not available. May be it is possible to create a custom Route and add it to route collection. – STO Jul 26 '12 at 19:57
  • I would like to do what this article does in PHP, but in VB http://stackoverflow.com/questions/2395325/dynamic-sub-domain-creation-with-php-in-a-linux-based-server?rq=1. It just looks at the subdomain and then sends to the correct controller/ route. I don't know where to begin with your suggestion. Do you have any examples? – user1477388 Jul 26 '12 at 20:02
  • I tried to make a quick research with writing a custom routes that takes care about subdomains but with no success. It seems not as simple as it looked like for me at first. When you derive your class from Route class you need to pass implementation of IRouteHandler interface and I can't figure out without source code and ReSharper what should I pass there. May be this http://stackoverflow.com/questions/379558/mvc-net-routing#379823 helps you. – STO Jul 26 '12 at 20:08
1

This is possible in MVC and has been answered before here on SO

See Previous Answer

In order for DNS to work, you will need to setup a wildcard subdomain so that any subdomain request for yourdomain.com will still point to your site. IIS will also need to be configured to listen for any and all request for any subdomain for your site. I cannot answer how to do this as I do not know your hosting configuration.

Community
  • 1
  • 1
Tommy
  • 39,592
  • 10
  • 90
  • 121