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:-
Created a "WeApi" folder in the root.
Created an API Controller called "ProductsController"
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" };
}
} }
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.
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.
Getting 404 WebApi
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:-
Here is the code:-
Do I need to add anything else? any config?
Could anyone help me?
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.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.is working on a reply...