【问题标题】:How to set up custom routing for wildcard subdomains in Nancyfx如何在 Nancyfx 中为通配符子域设置自定义路由
【发布时间】:2014-08-21 23:53:19
【问题描述】:

这个问题已经被问到here,但我不确定是否提供了足够的细节来提供答案。

我想实现自定义路由,使我能够根据 URL 的子域匹配路由段。

例如,我希望能够做类似这样的事情:

// This route should match where the URL is 
//    www.mysite.com
Get["/"] = _ => return "Home";

// This route should match where the URL is 
//    {anything else}.mysite.com
Get["/:subdomain"] = _ => return "Subdomain home";

我希望:subdomain 路由成为任何带有不是www.mysite.com 的URL 的请求的“包罗万象”。我可以检查正在访问的“虚拟子域”并相应地显示内容。

这是为了允许用户创建自己的帐户并接收自己的子域,例如joebloggs.mysite.com

我了解自定义路由是通过继承 TrieNode 来实现的,根据 Phill Haydon 的帖子 here。有没有一种方法可以让我从 Match 方法中访问完整的 URL?或者有更好的方法吗?

【问题讨论】:

    标签: c# routing nancy


    【解决方案1】:

    我认为您可以使用路由条件来做到这一点:https://github.com/NancyFx/Nancy/wiki/Defining-routes#condition 在路由条件中,您可以访问 NancyContext,这使您可以访问请求 URL。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 2019-02-25
      • 2015-11-23
      • 2020-02-03
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      相关资源
      最近更新 更多