【问题标题】:Subdomain routing in ASP.Net Core 5.0ASP.Net Core 5.0 中的子域路由
【发布时间】:2021-12-29 08:18:28
【问题描述】:

我有一个使用 dot net core 5.0 开发的应用程序,域为 india.com 现在我必须将动态子域绑定到域 india.com。 示例:br.india.com, sa.india.com, rs.india.com, ax.india.com, .... 等等。

具有挑战性的工作是我希望所有子域绑定都是动态的,而不是静态的。这将从数据库中处理。

任何人都可以帮助我。 提前谢谢你。

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: asp.net-core .net-core routes asp.net-core-routing


【解决方案1】:

您的网络服务器(IIS、Nginx、...)的基础有所不同:

IIS: web.config 需要添加重写角色:

将域重定向到子目录

<rule name="CustomRule" enabled="true" patternSyntax="Wildcard" stopProcessing="true">  
 <match url="*.mydomain.com" />  
 <action type="Rewrite" url="http://example.com/{R:0}" /> 
</rule>

Nginx:

server {
    listen      80;
    server_name *.example.com; 
    return 301 https://$host$request_uri;
}

【讨论】:

    猜你喜欢
    • 2021-05-04
    • 2019-05-17
    • 2022-10-24
    • 2018-08-28
    • 1970-01-01
    • 2016-03-23
    • 2016-12-01
    • 1970-01-01
    • 2019-07-21
    相关资源
    最近更新 更多