36

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.

9
  • 7
    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". Commented May 13, 2013 at 18:28
  • 2
    @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? Commented May 13, 2013 at 21:22
  • 2
    If you want to host them both under the same website, why not combine both projects into one? Commented May 13, 2013 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. Commented May 14, 2013 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. Commented May 14, 2013 at 14:04

3 Answers 3

73

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for making me learn something awesome today. Works like a charm.
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. :)
2

Coming late to the party but in case anyone else is looking for a solution, this is what was best for me: Set the Api project up to be the starting project (I needed to limit to one startup so that I could flip between browsers more easily). After firing up the service project, right click on the web/ui project and select debug, start new instance. You'll have both running and you'll seamlessly step from web to api.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.