如何使用ASP.NET创建动态子域? [英] How to Create Dynamic Sub-domain with ASP.NET?

查看:111
本文介绍了如何使用ASP.NET创建动态子域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net C#应用程序中创建子域?我正在使用一个asp.net门户。

How can I create a subdomain in an asp.net C# application? I am working with an asp.net portal.

我有我的网站将所有* .domain.com电话重定向到domain.com。我想要实现的是,首先当用户输入动态子域名时,他应该被引导到其主页,就像用户写入www.microsite1.domain.com一样,那么站点应该指向页面〜/ Microsite / Home.aspx ?value = microsite1,当用户访问www.microsite1.domain.com/about.aspx时,我应该能够得到参数value1 = about。

I have my site which redirects all *.domain.com calls to domain.com. What I want to acheive is that first when the user enters a dynamic subdomain name he should be directed to its home page like if user writes www.microsite1.domain.com, then the site should point to page ~/Microsite/Home.aspx?value=microsite1, and when the user accesses www.microsite1.domain.com/about.aspx then i should able to get the argument value1=about.

推荐答案

第一步是将子域名放在DNS主机服务器中。要做到这一点,您需要操纵dns文件。例如,如果您使用BIND作为DNS服务器,请打开保存DNS配置的文本文件,例如:c:\program files\dns\var\mysite.com,然后添加一行为

The first step is to place the subdomain name in the DNS Host Server. To do that you need to manipulate the dns files. For example if you use BIND as DNS server you go and open the text file that keep your DNS configuration eg: "c:\program files\dns\var\mysite.com" and there you add a line as

subdomain.mysite.com.   IN  A   111.222.333.444

此外,您还可以更改文件的ID,以向BIND发送消息以更新子域名。

Also you change the ID of the file to give a message to BIND to update the subdomains.

第二步是将新子域重定向到正确的目录。你可以在上保护void Application_BeginRequest(Object sender,EventArgs e)在 Global.asax 使用rewritepath

Second step is to redirect the new subdomain to the correct directory. You do that on the protected void Application_BeginRequest(Object sender, EventArgs e) on Global.asax using rewritepath

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    if (HttpContext.Current.Request.Url.Host.StartsWith("subdomain."))
    {
        // here you need to find where to redirect him by reading the url
        // and find the correct file.
        HttpContext.Current.RewritePath("/subdomain/" + Request.Path, false);
    }


    // .... rest code   
}

它不是那么容易,不是那么难...也许有一些更小的问题,如写入dns的权限。还需要知道dns,请阅读手册。

Its not so easy, not so hard... maybe there are some more minor issues like permissions to write to dns. Also you need to know dns, read the manual about.

这篇关于如何使用ASP.NET创建动态子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆