locked
How do I add an ApiController based site to an existing web site? RRS feed

  • Question

  • User683066381 posted

    I have a web site that I want to add an ApiController to that will handle an Ajax call from one of the web pages. There isn't much to the controller but I'm very confused about how to either add the controller to the existing web.config so that it will run or how to add the project to the current web site. Another issue is that the current web site is using .NET 4.0. I think the controller uses some of the more recent packages.

    Monday, March 24, 2014 3:12 PM

All replies

  • User-166373564 posted

    Hi,

    Please take a look at configuring ASP.NET Web API, and check whether it helps on this issue.

    # Configuring ASP.NET Web API

    http://www.asp.net/web-api/overview/extensibility/configuring-aspnet-web-api 

    Moreover, this is also available for us to use ApiController Class,

    # ApiController Class

    http://msdn.microsoft.com/en-us/library/system.web.http.apicontroller(v=vs.118).aspx 

    If you have any concern, please let me know.

    Regards

    Monday, March 24, 2014 11:02 PM
  • User683066381 posted

    Sorry to be such a boob but if I'd found the standard documentation any help, I wouldn't have asked the question here. Recommendations out side of read the documents would be greatly appreciated.

    Part of my issue is that my controller has to be added to the current web site because I am making an Ajax call from a standard HTML web page and Ajax calls outside the same location are blocked or problematic.

    Tuesday, March 25, 2014 10:21 AM
  • User683066381 posted

    I'm very sorry but I'm trying to follow the documents you linked to but the project was originally created in an earlier version of Visual Studio. I'm using VS 2013. The current solution is all using .NET 4.0. When I try to add the attributes, I can't find the references they are in to load them. Many of the asseblies that are used in my original proof of concept are in 4.5.

    What I'd like to do is just add a handler for a get that takes a value and returns a JSON response to one of the page's JavaScript. I thought I knew how to do this back when I was using VS 2010 but so much has changed.

    Tuesday, March 25, 2014 12:24 PM
  • User683066381 posted

    The original site must be on way too old of a version. There is not a GlobalConfiguration and a lot of the other classes described in your links. They simply don't exist in that version. What would I look at for much earleir versions?

    Wednesday, March 26, 2014 5:07 PM
  • User-166373564 posted

    Hi,

    Appreciate your feedback.

    Sorry to be such a boob but if I'd found the standard documentation any help, I wouldn't have asked the question here. Recommendations out side of read the documents would be greatly appreciated.

    Generally it's recommended to check whether you use ApiController properly, and we could give troubleshooting further, so I give the MSDN document above.

    For your issue, I think this example is also avialable to learn the procedure to use ApiController: How to add Web API to an existing ASP.NET MVC 4 Web Application project 

    In addition, if this issue is related to .NET frameworks versions, you could give more details to troubleshoot.

    Best regards

    Angie

    Wednesday, March 26, 2014 10:52 PM