Copied to clipboard

Flag this post as spam?

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


  • Manish Prajapati 4 posts 34 karma points
    19 days ago
    Manish Prajapati
    0

    I am very very new in Umbraco and ASP .Net. Actually, I have to create a web API in Umbraco so that my frontend can consume. I am using Umbraco 8. What I have done:-

    1. Created a "WeApi" folder in the root.
    2. Created an API Controller called "ProductsController"
    3. Then I am trying to hit "http://localhost:44314/umbraco/api/products/getproducts" but I am getting 404.

    Here is the code:-

    using System.Collections.Generic;
    using System.Web.Http;
    using Umbraco.Web.WebApi;
    using Umbraco.Core.Composing;
    using Umbraco.Core;
    namespace WebApplication30.Controllers
    {
    public class ProductsController : UmbracoApiController
    {
        [HttpGet]
        public IEnumerable<string> GetProducts()
        {
            return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" };
        }
    } }
    

    Do I need to add anything else? any config?

    Could anyone help me?

  • Kevin Jump 1753 posts 11263 karma points MVP 4x c-trib
    17 days ago
    Kevin Jump
    0

    Hi,

    The code looks fine (and works when I've just copied it into a test project).

    i suspect is its not being compiled by the site - so the API isn't there.

    If you are using Visual Studio you should check to see if the ProductsController.cs file has a build action of compile.

    enter image description here

    then when you build the site the code will be compiled into the site dll, and the api should be visible.

    Or use the App_Code folder

    if you are editing the files on the site, put the controller or the folder it is in inside a folder called App_Code - code inside this folder is then complied when the site starts up, and again this should make your API visible.

Please Sign in or register to post replies

Write your reply to:

Draft