How to handle subdomains in NancyFX routes

一笑奈何 提交于 2019-12-08 05:40:17

问题


Really liking the simplicity and the power of the NancyFX framework, but I ran into something which I cannot find a good solution for; how to route based on subdomains?

For example; I want to define a route that matches something like

{account}.website.com/restofroute

While having other parts of my site react to the normal www.website.com routing. So basically I want multi tenant support in my site based on the host name.

I found some ways to create and hookup a TrieNode so I can match the host header against some pattern and extract the account itself, but I don't see how I can link this up with the routes itself. Somehow I need to do this in the rootnode I think, so I override the GetMatches and add my local captures to it. Local captures are generated by some regex and contain something like {'account', 'www'}.

I thought I could create something like:

Get["/", a=>a.IsWwwRoute()] = parameters =>

Where IsWwwRoute is a method extension looking at the parameters collection for the account parameter that I included using the local captures. If set to 'www' let it pass, otherwise we use another route (which then uses the account parameter). But I cant find the value anywhere (parameters is null).

So what is the best way to add subdomain routing to NancyFX?

来源:https://stackoverflow.com/questions/17516972/how-to-handle-subdomains-in-nancyfx-routes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!