0

I created a solution with two webapplication project. One is asp.net mvc and second one is web api. Now I want to publish. Kindly suggest me how to publish my webapplication and webapi

hvojdani
  • 460
  • 3
  • 13

2 Answers2

0

all mvc pages, web api controllers and aspx pages can be added to single project, no need to different project, if you need to seperate business you can use areas and class libraries

hvojdani
  • 460
  • 3
  • 13
0

Process 1 :

You don't need to create separate project for Web API and MVC application in a single solution. You can create a MVC application and add an WebApiConfig.cs (route for api) file in App_Start folder. Write the route for API,(you just need to copy your route from Web API project and paste here). Now you can add/keep your all Api controllers in Controller folder which must be inherited from ApiController. That's it!

Process 2 :

But if you want to keep in separate project in a single solution,

then right click on your solution -> click on properties -> It will open property page. Here select the Multiple Startup projects radio button -> Then you can set both MVC and Web API application as start in action column -> Click on Apply -> Then Ok.

Suppose your Domain name is example.com. Then you can publish your MVC application there. And create a sub-domain, for example, myapi.example.com, and publish your API there. Then enable CORS on API project.

I would recommend to go with Process 1.

If you want to know more about how to publish both project from a single solution, please check this link

Community
  • 1
  • 1
Basanta Matia
  • 1,504
  • 3
  • 15
  • 27
  • But How to publish and host my web application. – sumit kumar Apr 03 '17 at 06:31
  • As I stated, it's very easy to keep your both projects in a single one then publish. – Basanta Matia Apr 03 '17 at 06:40
  • I have done above given process. Right click on your solution -> click on properties -> It will open property page. Here select the Multiple Startup projects radio button -> Then you can set both MVC and Web API application as start in action column -> Click on Apply -> Then Ok Then publish web application. But I have one issue. In my web application I am using web api url "http://localhost:51673/". – sumit kumar Apr 03 '17 at 08:00
  • Ok. Are you able to publish ? – Basanta Matia Apr 03 '17 at 08:02
  • It show only one application. but not show web api. – sumit kumar Apr 03 '17 at 08:05