0

I have a project running mvc 5 and web api 2.2 together, however each one has their own routing sytem.

The problem is that both respond to api.domain.com and both respond to www.domain.com

So I need that the api.domain.com would not have anything to do with, for instance, api.domain.com/blog, which is a url that should only belong to www.domain.com/blog. Same way I should not be able to access www.domain.com/api/...

I was thinking about checking the url in the Application Requet and run an if statement there, however it does not sound right to me.

Is it a matter of splitting them into two separate projects under the same solution and cross reference the projects/libraries?

WPalombini
  • 691
  • 9
  • 25
  • possible duplicate of [Is it possible to make an ASP.NET MVC route based on a subdomain?](http://stackoverflow.com/questions/278668/is-it-possible-to-make-an-asp-net-mvc-route-based-on-a-subdomain) – Brad Christie Nov 03 '14 at 00:31
  • 1
    separate the projects in the same solution :) – Martin Solev Nov 03 '14 at 00:42

1 Answers1

1

You could use the IIS URL Rewrite module to rewrite requests to api.domain.com/... to /api/... and www.domain.com to /web/.... Now you can have entirely separate routes within the application.

Or you could create a custom action filter that checks the domain and apply that to each class or method to constrain it to only respond to that domain. Or course you'd need a separate action filter for MVC and WebAPI but that's another story ...

Ian Mercer
  • 38,490
  • 8
  • 97
  • 133