How do I debug a web api RRS feed

  • Question

  • User-1355245701 posted

    How do I debug a web api? I have my asp.net website in one copy of VS 2015 (community) and my client in another copy. Both access the same localhost. website. When I call a web api from my client it does not trigger a breakpoint in the website. The web api itself works outside of vs.

    Thursday, July 28, 2016 1:34 AM

All replies

  • User36583972 posted

    Hi trogan,

    How do I debug a web api?

    Firstly, you should run your Web API in VS.

    If your the applications are hosted at different domains, you may should Enabling Cross-Origin Requests in ASP.NET Web API 2.


    Then, we can call Web API from our client or some test tools.

    In our Asp.net client, we can use the following code.

            var baseUrl = Request.Url.GetLeftPart(UriPartial.Authority);
                string fullPath = baseUrl + "/api/Values";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullPath);
                request.Method = "Get";//post, put ...
                request.KeepAlive = true;
                request.ContentType = "appication/json";
                //request.ContentType = "application/x-www-form-urlencoded";
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                string myResponse = "";
                using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()))
                    myResponse = sr.ReadToEnd().ToString();

    Some tools can help your test your Web API. You can refer the following link.

    Testing Tools for web API:


    Best Regards,

    Yohann Lu

    Thursday, July 28, 2016 2:32 AM
  • User1869050296 posted

    run your api using vs, it should show the default api page with the localhost:portnumber, append your controller name/ method name, this should hit your breakpoint.

    If you want to use your client, point the uri to your running api with the portnumber as well, and then submit a post/get request to your method

    Thursday, July 28, 2016 3:08 AM
  • User-1355245701 posted

    Thx but not happening.

    Thursday, July 28, 2016 11:32 AM
  • User-1355245701 posted

    Thx. Am using same domains but breakpoints are not being hit.

    Thursday, July 28, 2016 11:34 AM
  • User36583972 posted

    Hi trogan,

    If you have already deployed Web API, then this cannot be debugged. In development mode (JS), we can be normal debugging.

    Best Regards,

    Yohann Lu

    Saturday, August 6, 2016 2:30 AM