可以在 ASP.Net 应用程序中以编程方式管理子域吗?

发布于 2024-08-06 16:18:20 字数 832 浏览 3 评论 0原文

我有一个用 ASP.Net 3.5 编写的应用程序,需要管理不同网站的子域。管理网站和受控网站托管在不同的 Windows 服务器上,但都运行 IIS 6.0。

管理网站需要提供一个 UI,可以在受控站点上添加或删除子域,以便对这些子域(即 mysubdomain.controlsite.com 和 thatothersubdomain.controlsite.com)的请求导航到受控站点 Web 应用程序的不同部分(或者,如果需要将所有这些设置到不同的 Web 应用程序,那么也必须以编程方式创建或删除这些应用程序)。

我从哪里开始呢?这可能吗?我见过其他一些问题(是否可以基于子域创建 ASP.Net MVC 路由?)有关路由的信息,但我不知道这是否适合我的情况(我我没有使用 MVC)。我可以修改管理网站和受控网站上的代码,因此,如果需要进行编程以使其在任一端都能工作,我就可以这样做。

具体来说,如果代码保持在受控站点上的方式(如有必要,我可以更改),我需要接收类似 http://xxxx.mysite.com/ 并将其映射到 http: //www.mysite.com/Home/xxxx/ 同时保留客户端看到的 URL 为前者。

I have an application to be written in ASP.Net 3.5 that needs to manage subdomains for a different website. The managing website and the controlled website are hosted on different Windows servers, but both run IIS 6.0.

The management website needs to provide a UI that can add or delete subdomains on the controlled site such that requests to those subdomains (i.e., mysubdomain.controlledsite.com and thatothersubdomain.controlledsite.com) navigate to different sections of the controlled sites web application (or, if necessary to set all of this up, to different web applications, which then also have to be created or deleted programmatically).

Where do I get started with this? Is this even possible? I've seen on some other SO questions (Is it possible to make an ASP.Net MVC route based on a subdomain?) something about routes, but I don't know if that fits my situation or not (I'm not using MVC). I can modify the code on both the management website and the controlled website, so if there is programming to be done to make this work on either end, I can do that.

To be specific, if the code stays the way it is on the controlled site (I can change if necessary), I need to receive requests like http://xxxx.mysite.com/ and map that to http://www.mysite.com/Home/xxxx/ while keeping the URL that the client sees as the former.

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

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

发布评论

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

评论(2

梦归所梦 2024-08-13 16:18:20

您可以通过使用 URL 重写来实现此目的,您可以在 ASP.Net 中通过编写 HTTP 模块(实现 IHttpModule 的类)并使用 HttpContext 对象的 RewritePath 方法来实现

您可以设计您的模块因此它会根据一些配置文件重写 URL,您的管理应用程序可以根据需要更改这些配置文件。

以下链接详细解释了这些概念:

对于 IIS 6,这些配置可能会稍微复杂一些,请搜索有关配置通配符路径的文章。
另外,我不完全确定这种方法是否适用于子域。

You could possibly achieve this by using URL rewriting which you can do in ASP.Net by writing a HTTP Module (a class that implements IHttpModule) and using the RewritePath method of the HttpContext object

You could design your module so it rewrites URLs based on some configuration file which your management application can alter as appropriate.

The following links explain the concepts more:

With IIS 6 configuration of these can be slightly trickier, search for articles on configuring wildcard paths.
Plus I'm not entirely sure if this approach will work with subdomains or not.

浮华 2024-08-13 16:18:20

asp.net MVC 中包含的默认路由框架无法使用 URL 的域部分。我自己对此感到有点失望。但是有一篇关于使用自定义 RouteBase 来启用子域场景。我还没有尝试过,所以我不能保证所描述的技术,但它至少作为一个起点看起来很有希望。

至于管理所有这些的网络管理工具......您将需要推出自己的管理工具。如何做到这一点很大程度上取决于应用程序的设计方式。我只需将两个应用程序绑定到同一个 SQL 数据库来存储每个子域路由。其管理界面应该相当简单。您只需要一组相当简单的页面来对数据库中存储的路由执行 CRUD 操作。

在另一个站点(公共站点)的 global.asax 中,您只需从数据库中获取路由并单独注册每个路由。

The default routing framework included with asp.net MVC cannot use the domain portion of URLs. I was a tad disappointed by that myself. But there is an article about using a custom RouteBase to enable the subdomain scenario. I haven't tried it yet though so I can't vouch for the technique described, but it looks promising as a starting point at least.

As for the admin web tools to manage all that... you will need to roll your own admin tools. How you do that depends a lot on how your applications are designed. I'd just tie both apps to the same SQL database to store each subdomain route. The admin interface for that should be rather trivial. Just a rather simple set of pages to do the CRUD operations on the routes stored in the DB is all you'd need.

In the global.asax of the other site (the public one) you'd just fetch the routes from the DB and register each one individually.

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