Reputation: 678
I have followed Maarten Balliauw's post on domain routing. I had been able route to controller's for different sub-domains. But I don't know how to route to a virtual directory. As you see this is a sample example for routing to usual mvc controllers,
routes.Add("DomainRoute", new DomainRoute(
"home.example.com", // Domain with parameters
"{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
));
As my blog resides on Virtual Directory I need to add the route to this virtual directory named "~/blog" I have tried code like this with no good result,
routes.Add("DomainRoute", new DomainRoute(
"blog.domain.com", // Domain with parameters
"blog", // URL with parameters
new { controller = "blog" } // Parameter defaults
));
If anyone can bring some light into this it will be amazing.
Upvotes: 2
Views: 1994
Reputation: 384
You could try to make the blog an MVC Area of your main web application. You create a new Area called blog. This creates a Folder called "Areas/blog" in your main webroot. You can then turn the 'blog' folder into a virtual directory pointing to your blog application.
I did this in a recent web project for my admin backend. I used this blog post and it worked great. Very simple and keeps your application nice and clean.
http://bob.archer.net/content/aspnet-mvc3-areas-separate-projects
When you are actually inside the 'blog' area your actionlinks and everything works like normal. You only need to add "Area = 'blog'" to your links that move you from area to area.
Once you create the blog area take a look at the routes file it creates. I hope that makes sense.
Upvotes: 2
Reputation: 1650
The implication here is that the virtual folder is completely distinct from the MVC application it's within -- if that's the case, do you need to use the MVC routing at all, since you don't need any of the MVC resources to begin with? It would probably be easier just to configure the subdomain to point at the appropriate folder within IIS, and bypass MVC's routing altogether.
Upvotes: 0