简体   繁体   English

ASP.NET 5中的子域路由

[英]Subdomain routing in ASP.NET 5

I am trying to get sub-domain routing working in my ASP.NET 5 application. 我试图让我的ASP.NET 5应用程序中的子域路由工作。

I basically want to map http://api.example.com to a particular controller within my application, http://map.example.com to a different controller etc. 我基本上想将http://api.example.com映射到我的应用程序中的特定控制器, http://map.example.com到不同的控制器等。

I have looked at various articles about this but they are all out of date and do not work with the latest version of the ASP.NET framework. 我查看过有关此内容的各种文章,但它们都已过时,不适用于最新版本的ASP.NET框架。

The official documentation is missing information on routing. 官方文档缺少有关路由的信息。 Maybe it's my own fault for trying to use a beta product! 尝试使用测试版产品可能是我自己的错!

Looking forward to hearing some ideas of how to get this working. 期待听到一些关于如何使这个工作的想法。

If I understand your intent correctly, ASP.NET routing is not the proper way for this. 如果我理解你的意图,ASP.NET路由不是正确的方法。

If this was for ASP.NET versions before 5.0, I'd have suggested that you intercept the request before it's routed within Application_BeginRequest() and check for HTTP_HOST Request Header value to determine which site the user wanted to visit. 如果这是针对5.0之前的ASP.NET版本,我建议您在请求在Application_BeginRequest()中路由之前拦截该请求,并检查HTTP_HOST请求标头值以确定用户想要访问的站点。

I see that the application flow has changed in a major way with vNext. 我看到应用程序流已经以vNext的主要方式发生了变化。 However, I came across this sample from the ASP.NET MVC 6 source on github that creates a custom route based on a "User" header in the request: https://github.com/aspnet/Mvc/tree/dev/samples/CustomRouteSample.Web I believe this may be the starting template for a similar solution to your issue if you use "HTTP_HOST" header instead. 但是,我从github上的ASP.NET MVC 6源代码中看到了这个示例,它根据请求中的“User”标题创建了一个自定义路由: https//github.com/aspnet/Mvc/tree/dev/samples /CustomRouteSample.Web我相信如果您使用“HTTP_HOST”标头,这可能是您的问题的类似解决方案的起始模板。

Good luck, let us know if you're able to implement a working solution. 祝您好运,如果您能够实施可行的解决方案,请告诉我们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM