简体   繁体   English

替代ASP.NET虚拟目录以实现多租户

[英]Replacement for ASP.NET Virtual Directory for Multi-tenancy

I am working on an ASP.NET WebForms Application, using ASP.NET 4.5 我正在使用ASP.NET 4.5开发ASP.NET WebForms应用程序

The Application has multi-tenancy support. 该应用程序具有多租户支持。 Each tenant has an own URL like: 每个租户都有自己的URL,例如:

http://myApplication.net/DemoTenant1/ http://myApplication.net/DemoTenant1/

Very simplified in the Login.aspx the application calls this method and translates this URL to an internal ID. 在Login.aspx中非常简化,应用程序调用此方法并将此URL转换为内部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 现在的问题是,我们有200多个租户,每个租户都需要定义一个WebApplication,

  • 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? 我正在寻找一个想法,如何通过URL路由解决此问题,或者如何将WebForms与MVC混合并添加登录控制器?

Also open to other ideas... 也欢迎其他想法...

I agree with what Alexander said, the proper way to do this would be with URL Routing. 我同意亚历山大所说的话,正确的方法是使用URL路由。 But... If you are trying to save time... 但是...如果您想节省时间...

First, remove all of your web applications; 首先,删除所有Web应用程序;

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. ...将您带到您要使用的实际WebApplication。

Then, in the global.asax file... you need to capture 404 exceptions. 然后,在global.asax文件中,您需要捕获404异常。

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: ...它将引发404异常,您可以像这样在global.asax文件中捕获该异常:

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). 但是,您现在确实具有Microsoft构建的路由模块(当时我没有)。 I am quite sure that you can use the Routing modules within Webforms, without having to use MVC. 我非常确定您可以在Webforms中使用“路由”模块,而不必使用MVC。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM