Subdomain routing in ASP.NET 5

I am trying to get the routing of subdomains running in my ASP.NET 5 application.

I basically want to map http://api.example.com to a specific controller in my application, http://map.example.com to another controller, etc.

I have looked at various articles about this, but they are all outdated and do not work with the latest version of the ASP.NET framework.

There is no routing information in the official documentation . Perhaps this is my own mistake for trying to use the beta product!

Looking forward to some ideas on how to do this.

+7
asp.net-mvc asp.net-web-api asp.net-core
source share
1 answer

If I understand your intent correctly, ASP.NET routing is not suitable for this.

If this were for ASP.NET versions prior to 5.0, I would suggest that you intercept the request before routing it in Application_BeginRequest () and check the value of the HTTP_HOST request header to determine which site the user should visit.

I see that the application flow has changed a lot with vNext. However, I came across this sample from an ASP.NET MVC 6 source on github that creates a custom route based on the User header in the request: https://github.com/aspnet/Mvc/tree/dev/samples/ CustomRouteSample.Web I believe this may be the original template for a similar solution to your problem if you use the "HTTP_HOST" header instead.

Good luck, let us know if you can implement a working solution.

-2
source share

All Articles