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.
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:
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
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:
Where "yourwebproject.Umbraco.Web" is the Umbraco website.
Hope this helps a bit :-)
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
is working on a reply...