如何在MVC中创建动态子域? [英] How to Create Dynamic SubDomain in MVC?

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

问题描述

我将我的网站托管为www.sample.com,但我需要

i have hosted my site as www.sample.com but i need

  • -user1.sample.com
  • -user2.sample.com
  • -user3.sample.com

有可能吗?每个用户作为子域名.

Is It Possible? every User as SubDomain Name.

推荐答案

您实际上并没有创建"新的子域-而是设置通配符"条目作为所有未解析名称的通用名称:

You don't actually "create" new subdomains - instead you set-up "wildcard" entries that serve as catch-alls for all unresolved names:

  1. 您需要通配符DNS记录,以便所有子域都解析为相同的主机(IP)地址.并非所有的DNS提供商都提供此服务,因此您可能需要在必要时切换DNS服务的提供.
  2. 然后,您需要配置Web服务器以处理这些请求.您有两种选择:
  1. You need a wildcard DNS record so that all subdomains resolve to the same host (IP) address. Not all DNS providers offer this service, so you may need to switch DNS service provides if necessary.
  2. You then need to configure your web-server to handle these requests. You have two options:
  1. 使用终结点绑定(这样您的IIS网站将处理对给定IP地址和端口号的所有请求).在IIS 10.0之前,这是支持通配符或任意子域的唯一方法.这种方法需要为每个网站使用单独的IP地址.
  2. 使用正确的通配符域绑定. (IIS最终在版本10.0中添加了对此功能的支持)[0](IIS 10.0与Windows 10和Windows Server 2016一起发布). IIS 8.5或更早版本不支持此功能.
  1. Use an endpoint binding (so your IIS website will handle all requests to a given IP address and port-number). Until IIS 10.0 this was the only way to support wildcard, or arbitrary, subdomains. This approach requires a separate IP address for each website.
  2. Use a proper Wildcard Domain binding. (IIS finally added support for this feature in version 10.0)[0] (IIS 10.0 was released with Windows 10 and Windows Server 2016). This is not supported in IIS 8.5 or earlier.

  • 您的应用程序代码需要检查HTTP Host:标头,以确定所检查的内容.如果将ASP.NET与路由一起使用(ASP.NET MVC自动进行路由),则可以使用自定义RouteBase子类,以使您可以在路由中使用Host头值,如以下示例所示: http://benjii.me/2015/02/subdomain-routing-in- asp-net-mvc/
  • Your application code needs to inspect the HTTP Host: header to determine what was inspected. If you're using ASP.NET with Routing (which ASP.NET MVC does automatically) you can use a custom RouteBase subclass to let you use Host header values in routes, as per this example: http://benjii.me/2015/02/subdomain-routing-in-asp-net-mvc/
  • 请注意,步骤2的两个选项都需要客户服务器配置选项(IP地址绑定或正在运行Windows Server 2016).如果您使用共享主机提供商(HostGator,DreamHost等-甚至Azure网站),则该服务将对您不可用,因为他们通常不向其客户提供这些服务-但无论如何都要询问他们是否可以支持你.

    Note that both options for Step 2 require customer server configuration options (either an IP-address binding, or to be running Windows Server 2016). If you're using a Shared-hosting provider (HostGator, DreamHost, etc - even Azure Websites) then this will not be available to you as they typically don't offer those to their customers - but ask them anyway to see if they can support you.

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

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