Creating a domain route
In this recipe, we will learn how to create a domain route.
Getting ready
There are some scenarios where domain routing could be very useful and interesting:
- URLs can be as follows when using multi-lingual web applications:
route like "www.{language}-{culture}.domain.com" or "www.{language}.domain.com"
- URLs can be as follows when using multi-tenant web applications:
route like "www.{controller}.domain.com", "www.{area}.domain.com", "www.{subentity}.domain.com"
How to do it...
Let's just add new routes to Startup.cs
:
public void Configure(IApplicationBuilder app) { app.UseMvc(routes => { routes.MapRoute( name: "DomainRoute", template: "home.domain.com/{action=Index}/{id?}"); routes.MapRoute( name: "DomainRoute2", template: "{controller=Home}.domain.com/{id?}"); routes.MapRoute( name: "DomainRoute3", template: "{controller=Home}-{action=Index}.domain.com/{id?}"); } }