locked
MVC / WebApi in two separate projects? RRS feed

  • Question

  • User1781614048 posted

    Hi!

    I want to build a new web application using MVC 5. All data access should be done via knockout.js and ApiControllers as shown in this example: http://www.windowsazure.com/en-us/develop/net/tutorials/rest-service-using-web-api/. I don't want to mix "normal" Controllers and ApiControllers in one project but use two separate projects in my solution for this. Both projects should be called via the same url, e.g. homecontroller: "www.mysite.com/home", valuescontroller: "www.mysite.com/api/values". Is this possible and if yes, how do I configure the two projects to support this scenario?

    TIA
    Heiko

    Sunday, January 5, 2014 10:07 AM

Answers

  • User1066278571 posted

    Hi Heiko

    Yes you can do this on the IIS, but maybe you don't require this level of separation.

    You could add both the Web API and the MVC to the same web application but use different areas for both. One area for Web API and one for MVC.

    This would be less complicated to deploy etc. And you also have everything separated. You can configure both areas then as you wish, routes, security, as you require.

    Keep it simple.

    greetings Damien

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 5, 2014 10:51 AM

All replies

  • User1066278571 posted

    Hi Heiko

    Yes you can do this on the IIS, but maybe you don't require this level of separation.

    You could add both the Web API and the MVC to the same web application but use different areas for both. One area for Web API and one for MVC.

    This would be less complicated to deploy etc. And you also have everything separated. You can configure both areas then as you wish, routes, security, as you require.

    Keep it simple.

    greetings Damien

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 5, 2014 10:51 AM
  • User1781614048 posted

    Thanks Damien, I didn't think about that possibility and will give it a try.

    If it is not too much work for you: how would you configure my scenario in IIS? And what about having a subdomain for the webapi-part (api.mysite.com)?

    Best
    Heiko

    Monday, January 6, 2014 12:17 PM
  • User1066278571 posted

    Hi Heiko

    Sorry for taking so long to get back to you.

    1. Create a new website in the IIS.

    - Sites, right click and add website. add you website etc.

    2. Right click your new website and Add Application. Set the base path to api.

    3. Change the routing of your WebApi2 project.

    Per default you will have http://<>/api/api/ValuesController

    You want to remove one  <api>

    If you use Attribute Routing just set the Controller Route to "".

    See the Attribute Routing documentation on this site for full details

    http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2

    hope this helps

    greetings Damien

    Friday, January 10, 2014 3:44 AM