Domanda

I've done a lot of searching on this, and I know it's a common discussion point on this site, but none of the things I've found answer my (seemingly simple) question.

My situation is that I have an MVC web application running in IIS and I've recently started to build a WebAPI to provide a CRUD interface to the underlying data model.

These are separate projects in Visual Studio and run fine in isolation.

My issue is how to deploy them to IIS and how to configure it so

http;//myhost/Customers/Report

calls the MVC stuff but

http//myhost/api/Customers/123

calls the WebAPI.

I've seen various examples of deploying a WebAPI but they quietly include a different port number into the URL. I wanted to avoid something like this ...

http//myhost:8080/api/Customers/123

Is there a common pattern for this in terms of IIS config (nested application in the MVC tree, or a virtual directory)?

and/or

Do I need to put some code in the routing of the MVC application to direct to the WebAPI one?

Any help or referrals appreciated.

(FYI : Just two examples of what I've read are below but I've read about 20 articles so far)

How to add Web API to an existing ASP.NET MVC 4 Web Application project?

Problems (retroactively) adding Web API to asp.net MVC project

È stato utile?

Soluzione

Putting up the Route configuration should help you. Register WebApi route path first then the MVC application routes so that API is handled with web API and if its not API then it goes to MVC controller. This works for me.

This link might help on how to create virtual directories.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top