Multiclient application (multi-tenant) with asp.net webforms and routes

Question:

I am developing a multi-client web application for a SaaS and I would like each client to have a different URL to access their area in the application, for example:

http://mydomain.com/cliente1 http://mydomain.com/cliente2

I thought of creating an application in IIS for each client, but this, in addition to being costly, can degrade the webserver's performance (I believe).

Is there any way to do this using routes?

Answer:

You need to change your route:

routes.MapRoute(
    name: "Default",
    url: "{cliente}/{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

And retrieve the value in the controller

public ActionResult Index(string cliente)
{
    return View(cliente);
}
Scroll to Top