2

我正在开发一个项目,您可以使用您的公司名称订阅该项目,并且您可以使用特定于您公司的网站的所有功能。例如,公司 abcd 可以从我们的网站获取自己的网址,例如

www.test.com/abcd/productlist.aspx

efgh 公司也可以使用自己的 url 登录并查看其产品列表。

www.test.com/efgh/productlist.aspx

任何人都可以帮助我如何以最佳方法在我的网站上实现这一点

我正在考虑使用 Global.ascx 文件来区分公司的方法,我将编写代码以从 global.ascx 中的 url 中为每个有效请求提取公司名称,并且在所有页面中我将放置 this.form.action = request .rawurl。

还有其他方法吗?如果有人实现了此类功能,请告诉我您的方法。

谢谢

4

4 回答 4

1

如果您使用的是 ASP.NET 3.5 SP1,那么您应该研究从 MVC 项目中引入的新路由引擎。这将是一个干净的解决方案。

于 2010-01-18T07:31:05.513 回答
1

我们使用来自http://urlrewriting.net的 DLL和类似于以下的规则:

<urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
  <rewrites>
    <add name="Customer" virtualUrl="^~/([^/]+)/([^/]+).aspx" destinationUrl="~/$2.aspx?customer=$1"/>
    <add name="CustomerStart" virtualUrl="^~/([^/]+)/$" destinationUrl="~/Default.aspx?customer=$1"/>
    <add name="CustomerStartAddSlash" virtualUrl="^http\://([^/]+)/([a-zA-Z0-9_-]+)$"
                                      destinationUrl="http://www.example.com/$2/"
                                      redirect="Domain" redirectMode="Permanent" />
  </rewrites>
</urlrewritingnet>

这些规则执行以下映射。这些是rewrites,所以用户总是在他的浏览器中看到左边的 URL:

Rule 1: http://www.example.com/customerA/something.aspx => http://www.example.com/something.aspx?customer=customerA
Rule 2: http://www.example.com/customerA/ => http://www.example.com/Default.aspx?customer=customerA

第三条规则是重定向而不是重写,即,它确保在用户的浏览器中添加尾部斜杠(确保相对路径正常工作):

Rule 3: http://www.example.com/customerA => http://www.example.com/customerA/
于 2010-01-18T08:33:10.443 回答
0

看看这些 问题
你的方法有一个名字。它称为多租户

于 2010-01-18T07:25:03.547 回答
0

我没有找到任何完全符合我要求的解决方案,我为此编写了自己的逻辑,它使用 Global.ascx 的 BeginRequest、登录页面、基本页面和为Response.Redirect. 我不再直接使用 Asp.Net 的Response.Redirect、 Paths 和 Session 变量,而是在它们之上创建了包装器,以将 companyName 从 url 添加到 Paths。

如果您需要有关我的代码的更多信息,请告诉我

欢迎其他答案。

谢谢

于 2011-11-05T13:30:50.610 回答