问题
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