Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

In VS 2012, I am attempting to create an MVC 4 web application with jQuery calls to a Web API project. (Other devs will be consuming the API with our current, native app, and probably adding to the API in the future.) So I have one project that is the Web API, and another project that is the MVC 4 website. I can only set one of them to run, and they use localhost:xxxxx.

How do I debug changes to both? For example, let's say I add a new API path /api/customer/get and then a new jQuery ajax call to that path and do something with the resulting JSON. I've changed code in both projects and want to follow it end-to-end; how do I launch both? How do I debug both?

Just to be clear, the MVC app isn't making server-side calls to the API, I'm using MVC mostly to be able to easily use bundling, minification, and (hopefully) pre-compiled Handlebars templates in .NET; the API calls are coming from jQuery. As I am still relatively new to these technologies, alternate suggestions are welcome.

Thank you in advance.

share|improve this question
5  
You can right-click on the solution in Solution Explorer and choose "Set Startup Projects..." then select "Multiple Startup Projects" and when you debug, you can hit breakpoints in all the projects that have an action of "Start". – Dan Liebster May 13 '13 at 18:28
1  
@TDL: That works, thanks. But it's exposed another problem in that each project is attached to a different localhost port number, in effect making them different websites (and domains?). The plan is to deploy to the same site, but the API routes all start with '/api/'. As it stands, how do I make my jQuery calls reference the correct domain when debugging? I certainly don't want to replace the URL in Debug mode, and then it seems like I'm getting cross-domain access problems. Does that make sense? – Jammerms May 13 '13 at 21:22
1  
If you want to host them both under the same website, why not combine both projects into one? – LordHits May 13 '13 at 21:44
    
@Jammerms - sounds like you are hard-coding your URLs into your code, which is not a good idea. Stuff like that should be in web.config. You can override them with transformations based on the deployment target environment. – Dan Liebster May 14 '13 at 13:25
    
@LordHits: I think we will end up combining them just to make things easier, but we wanted to have separation of concerns if possible and the ability for the API to be developed and deployed separately from the web site. – Jammerms May 14 '13 at 14:04
up vote 46 down vote accepted

I had the same problem and have found a solution from here:

forums.asp.net

The fix is to do the following:

In your solution file, click properties go to the Startup project node (if it is not already selected)

Next select Multiple startup projects. Select your website and your webservice and in the Action column make sure both of them have "Start" selected.

Now when you debug your website and put a break point in your webservice, it should hit the break point.

share|improve this answer
2  
This should be the answer. – Tony Jun 24 '14 at 20:11
    
Thanks for making me learn something awesome today. Works like a charm. – Vikram Sharma Feb 5 '15 at 6:30
    
Excellent. I have an ASP.net MVC (UI) project and another one to my WebAPI Service with this tip I can publish and DEBUG both at same time. :) – Ygor Thomaz Mar 29 '15 at 17:03

I had a similar problem with my web api project. My solution consisted of an angular front end with 2 web api projects on the backend. One web api project handled "authorization" and the other handled "resources". I used the following tutorial by Taiseer Joudeh as a starting point:

http://bitoftech.net/2014/09/24/decouple-owin-authorization-server-resource-server-oauth-2-0-web-api/

Breakpoints worked on the "authorization server"... but not on the "resource server". I compared the packages from the two projects to see what was different. Once I added "Microsoft.AspNet.WebApi.Cors" to the "resource server" project, the breakpoints starting working.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.