سؤال

I am working on an ASP.NET WebForms Application, using ASP.NET 4.5

The Application has multi-tenancy support. Each tenant has an own URL like:

http://myApplication.net/DemoTenant1/

Very simplified in the Login.aspx the application calls this method and translates this URL to an internal ID.

public static string getTenant(HttpRequest request)
{
    return = request.Url.ToString();       
}

The problem is now, we have more than 200 tenants, for each we need to define an WebApplication which is

  • a bunch of work :-)
  • probably very inefficient as an own worker process for each tenant is opend

I am looking for a smart replacement where I stay compatible to the old URLs.

I am looking for an idea how to solve this via URL Routing or maybe to mix WebForms with MVC and add a Login Controller?

Also open to other ideas...

هل كانت مفيدة؟

المحلول

I agree with what Alexander said, the proper way to do this would be with URL Routing. But... If you are trying to save time...

First, remove all of your web applications;

So get rid of...

http://myApplication.net/DemoTenant1/
http://myApplication.net/DemoTenant2/
http://myApplication.net/DemoTenant3/

And then you need to make sure that typing in the following:

http://myApplication.net/

... takes you to the actual WebApplication you want to use.

Then, in the global.asax file... you need to capture 404 exceptions.

So when someone types in:

http://myApplication.net/DemoTenant1/

... it will throw a 404 exception which you could catch in your global.asax file like this:

void Application_Error(object sender, EventArgs e)
{
    string urlData = Request.ServerVariables["SCRIPT_NAME"];

    // do some string splitting to get the DemoTenant1 value
    // Response.Redirect("~Login.aspx?tenant=DemoTenant1");
}

Its a bit messy but I have done this in the past when I was in exactly the same situation as you. Although, you do now have the routing module built by Microsoft (which I did not have at the time). I am quite sure that you can use the Routing modules within Webforms, without having to use MVC.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top