Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • lj 81 posts 425 karma points
    Aug 05, 2014 @ 20:31
    lj
    0

    setting up web api with umbraco 6.1.1

    Hi,

     

    Im trying to set up a web api controller within an umbraco 6.1.1 website.

    After reading http://our.umbraco.org/documentation/Reference/WebApi/. I created a new folder called controllers and added a new ProductsController.cs file to it.

    public class ProductsController : UmbracoApiController {

    public IEnumerable<string> GetAllProducts() {

    return new[]  "Table", "Chair", "Desk", "Computer", "Beer fridge" };

    }

    }

    compiled the project and no errors tried accessing it in browser using http://localhost:49645/Umbraco/Api/Productss/GetAllProducts but it returns a 404 not found error.

    Anyone any idea what im doing wrong.

     

    thanks lj

     

     

     

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Aug 07, 2014 @ 13:54
    Bo Damgaard Mortensen
    100

    Hi lj,

    How is your structure exactly? Have you added a folder named "Controllers" in the root of your Umbaco site, or have you created a separate project for your controllers, moving the dll to the Umbraco sites /bin folder?

    If you have created a folder called "Controllers" in the root of your website, try to move the controller to the App_Code folder (not recommending placing code in this folder though) I just did that on my testproject here and the controller gave me the result array just fine.

    Also, it looks like you have a typo in your URL: /Umbraco/Api/Productss/GetAllProducts there's an "s" too much in "Productss" ;-)

    Recommended approach (at least in my eyes) is to have a separate project for your sourcecode (including the controllers) where you have your Models, Controllers, Interfaces etc. folders and then make a copy on the post build event to copy over the dll when the project is built. The copy command could look like this:

    copy "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)yourwebproject.Umbraco.Web\bin\$(ProjectName).dll"

    Where "yourwebproject.Umbraco.Web" is the Umbraco website.

    Hope this helps a bit :-)

  • lj 81 posts 425 karma points
    Aug 07, 2014 @ 19:06
    lj
    0

    hi.

    I tried moving the controller folder into app_code folder but did not work.

    Once i moved it out into a separate class library project it worked great.

    Thanks for the advice

    lj

Please Sign in or register to post replies

Write your reply to:

Draft