如何为许多公司创建单个 Web 应用程序作为子域

发布于 2024-08-17 19:59:31 字数 431 浏览 4 评论 0原文

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

www.test.com/abcd/productlist.aspx

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

www.test.com/efgh/productlist.aspx

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

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

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

谢谢

i am working on a project that you can subscribe with your company name and you can use all features of site specificly to your company.
for example company abcd can get its own url from our website like

www.test.com/abcd/productlist.aspx

company efgh can also login with its own url and see its product list.

www.test.com/efgh/productlist.aspx

can any one help me how can i implement this with my site with best approaches

I am thinking on the approach that will use Global.ascx file to distinguish companies,
i will write code to extract company name from url in global.ascx for every valid request and in all the pages i will put this.form.action = request.rawurl.

is there any other approaches?
if anybody implemented this type of feature, please let me know your approaches.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

匿名的好友 2024-08-24 19:59:31

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

If you're working with ASP.NET 3.5 SP1 then you should investigate the new routing engine that has been introduced from the MVC project. It will make for a clean solution.

野味少女 2024-08-24 19:59:31

我们使用 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>

这些规则执行以下映射。这些是重写,因此用户总是在浏览器中看到左侧的 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/

We are using the DLL from http://urlrewriting.net and rules similar to the following:

<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>

Those rules do the following mappings. These are rewrites, so the user always sees the left-hand URL in his browser:

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

The third rule is a redirect rather than a rewrite, i.e., it ensures that the trailing slash is added in the user's browser (makes sure that relative paths work correctly):

Rule 3: http://www.example.com/customerA => http://www.example.com/customerA/
卖梦商人 2024-08-24 19:59:31

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

Take a look at these questions.
Your approach has a name. It's called Multitenancy.

飘落散花 2024-08-24 19:59:31

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

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

欢迎其他答案。

谢谢

I did not found any solution that fully suites my requirement , I have written my own logic for this , which uses Global.ascx's BeginRequest, Login page, Base page and common classes created for Response.Redirect. I am no longer directly using Asp.Net's Response.Redirect, Paths and Session variables, instead I have created wrappers over them to add companyName from url to the Paths.

Let me know if you need more information on my code

Other answers are welcome.

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文