如何在 ASP.NET 中创建子域并重定向到它们?

发布于 2024-07-11 02:26:42 字数 276 浏览 5 评论 0原文

如何在 ASP.NET 中创建子域? 我的主页(Home.aspx)上有几个链接 示例:Link1 和 Link2

我需要创建两个子域 link1.example.com 和 link2.example.com 并重定向到他们。 我将使用 Response.Redirect 进行导航。

问题: 这些文件是否需要驻留在不同的目录或其他目录中? 我可以在本地主机上测试或模拟这个示例吗?

对于这个新手 ASP.NET 程序员的任何帮助将不胜感激。

How do I create subdomains in ASP.NET?
I have few links on my homepage(Home.aspx)
Example: Link1 and Link2

I need to create two sub domains link1.example.com and link2.example.com
and redirect to them. I will be using Response.Redirect for navigation.

Questions:
Do the files need to reside in different directory or something?
Can I test or simulate this example on localhost?

Any help to this newbie ASP.NET programmer will be appreciated.

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

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

发布评论

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

评论(2

疯狂的代价 2024-07-18 02:26:42

根据您实际尝试通过这些重定向完成的任务,这可能很有用。 如果您只是尝试从单个 Web 应用程序处理多个子域,则可以完全使用托管单个 Web 应用程序的基于 IIS 的服务器以及 ISAPI 重写工具,在 ASP.NET 之外伪造此子域行为,例如Ionics Isapi 重写过滤器 (http://www.codeplex.com/IIRF),假设您有能够将 ISAPI 过滤器添加到您的托管环境。

由于 ISAPI 过滤器是在 ASP.NET 知道请求之前就已处理的,因此您可以仅从一个 Web 应用程序托管多个子域(和完整域)。 不幸的是,在 ASP.NET 内置 Web 服务器 (Cassini) 中模拟这种类型的重定向是不可能的,因为它不使用 ISAPI。 此方法确实允许您测试最终子域的功能,但仅限于最终重定向位置; 您也无法真正测试 Cassini 中的原始域映射,因为 Windows 主机文件不允许使用端口规则。

如果您将单个应用程序设置为具有处理所有所需子域的功能的页面,则只需将对子域的请求重定向到单个应用程序中所需位置即可。 这可以像单个应用程序中的页面文件夹一样简单,用于处理新子域的所有逻辑。 以下是 Ionics 的一些示例重写规则,这些规则会将各个子域的请求发送到单个 Web 项目中的最终位置:

RewriteCond %{HTTP_Host} ^(?~new-sub-domain.yourdomain.com).*$ [I]
RewriteRule ^(.*)$ http://www.yourdomain.com/new-sub-domain$1 [I,R=302]
RewriteCond %{HTTP_Host} ^(?~another-new-sub-domain.yourdomain.com).*$ [I]
RewriteRule ^(.*)$ http://www.yourdomain.com/another-new-sub-domain$1 [I,R=302]
# '#' is a comment marker in the rewrite files
# [I] at the end means case-insensitive
# [L] at the end  means last rule (sending the request on but hiding the forward from the end user)
# [R] at the end  means an official redirect and can be used instead of [L] (the end user will then see a new request, such as a 301 redirect using [R=301])

这将导致对新子域的所有请求都转到现有项目中的目录 (/分别是新子域/和/另一个新子域/); 可以修改它以将它们发送到该项目中您想要的任何位置。

虽然这种方法允许您从单个应用程序托管多个子域(以及可能的多个完整域),但 ASP.NET Web 服务器 (Cassini) 内重定向/重写的限制将使您只能测试这些最终域的功能。位置(例如“/new-sub-domain/”)。

Depending on what you are actually trying to accomplish with these redirects, this may be useful. If you are trying simply to have multiple sub-domains handled from a single web application, you can fake this sub-domain behavior outside of ASP.NET entirely using an IIS-based server hosting a single web application with an ISAPI rewrite tool such as Ionics Isapi Rewrite Filter (http://www.codeplex.com/IIRF), assuming you have the ability to add an ISAPI filter to your hosting environment.

Since the ISAPI filter is handled before ASP.NET even knows about the request, you can host a number of sub-domains (and full domains) from just one web application. Unfortunately, emulating this type of redirect in the ASP.NET built-in web server (Cassini) is not possible because it doesn't use ISAPI. This method does allow you to test the functionality of your final sub-domains, but only at the final redirect location; you can't really test the original domain map in Cassini either since the Windows hosts file doesn't allow rules with ports.

If you set up your single application to have pages to handle the functionality of all of your desired sub-domains, you can simply redirect the request for the sub-domain into your single application at the desired location. This can be as simple as a folder of pages within your single application that handles all the logic for your new sub-domain. Here are some example rewrite rules for Ionics that will send requests for the various sub-domains to the final location in your single web project:

RewriteCond %{HTTP_Host} ^(?~new-sub-domain.yourdomain.com).*$ [I]
RewriteRule ^(.*)$ http://www.yourdomain.com/new-sub-domain$1 [I,R=302]
RewriteCond %{HTTP_Host} ^(?~another-new-sub-domain.yourdomain.com).*$ [I]
RewriteRule ^(.*)$ http://www.yourdomain.com/another-new-sub-domain$1 [I,R=302]
# '#' is a comment marker in the rewrite files
# [I] at the end means case-insensitive
# [L] at the end  means last rule (sending the request on but hiding the forward from the end user)
# [R] at the end  means an official redirect and can be used instead of [L] (the end user will then see a new request, such as a 301 redirect using [R=301])

This will cause all requests to the new sub-domains to go to a directory within your existing project (/new-sub-domain/ and /another-new-sub-domain/, respectively); this can be modified to send them wherever you want within that project.

While this approach allows you to host several sub-domains (and potentially several full domains) from a single application, the restriction on redirect/rewrites within the ASP.NET web server (Cassini) will leave you restricted to testing the functionality of these final location (e.g., "/new-sub-domain/").

不甘平庸 2024-07-18 02:26:42

您需要从域提供商(从您购买域名的地方)而不是从 ASP.NET 网站设置域和子域。

在本地,您无法对此进行测试,因为您只能访问 http://localhost 作为开发 Web 服务器。

You need to set up domains and sub-domains from your Domain Provider (from where you bought your domain name), not from your ASP.NET website.

Locally, you cannot test this because you can only access http://localhost as the dev web server.

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