Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
Is it possible to use Web API and WebForms or do I have to use MVC? By the way I'am using Umbraco 6.1.6.
If it's possible, should I create a folder named Controllers and add my ApiControllers there?
So if I refer to the example at http://our.umbraco.org/documentation/Reference/WebApi/
public class ProductsApiController : UmbracoApiController{ public IEnumerable<string> GetAllProducts() { return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" }; } }
It should be accessible from localhost:some:port/Api/ProductsApi/GetAllProducts right?
Do I need to setup some routing to make it work?
Thanks in advance /E
Is it possible to use Web API and WebForms or do I have to use MVC? By the way I'am using Umbraco 6.1.6
Yes
No: localhost:some:port/Umbraco/Api/ProductsApi/GetAllProducts Unless you include this UrlRewrite rule in your web.config:
<rule name="Umbraco Web-API"> <match url="^api/(.+)$" /> <action type="Rewrite" url="/Umbraco/Api/{R:1}" /> </rule>
Thanks, I'll missed the part "Umbraco" in the URL I think, will test again and report back.
/E
Hi again,
I'am not able to make it work.
My folder structure.
using System.Collections.Generic; using Umbraco.Web.WebApi; public class ProductsApiController : UmbracoApiController { public IEnumerable<string> GetAllProducts() { return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" }; } }
Trying to access the GetAllProducts method by this url: http://localhost:4635/Umbraco/api/ProductsApiController/GetAllProducts
but it just returns a 404 page.
You need to leave out the 'Controller' part, like I mentioned before: /Umbraco/Api/ProductsApi/GetAllProducts
Copy paste, is a bad thing :). Also tested with http://localhost:4635/Umbraco/api/ProductsApi/GetAllProducts
Still no go. Should also mention that it's not the 404 page generated by Umbraco, is a 404 page generated from IIS.
A more detailed description of the 404 page.
Detailed Error Information:
The physical path is point to MyProject\Umbraco\Api... which seems wrong.
Okay, I got it to work. It may be that I misunderstood something, but for others that made the same mistake might be helped by this.
Instead of creating a folder Controllers under the root, add the controller to the App_Code instead and everything works like a charm.
Like this:
I seems that i does not matter if the ProductsApiController.cs is inside a folder as long as it's located in the App_Code folder.
This also works:
Thanks again for the help kipusoep
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Use Web API with WebForms
Hi,
Is it possible to use Web API and WebForms or do I have to use MVC? By the way I'am using Umbraco 6.1.6.
If it's possible, should I create a folder named Controllers and add my ApiControllers there?
So if I refer to the example at http://our.umbraco.org/documentation/Reference/WebApi/
It should be accessible from localhost:some:port/Api/ProductsApi/GetAllProducts right?
Do I need to setup some routing to make it work?
Thanks in advance /E
Yes
Yes
No: localhost:some:port/Umbraco/Api/ProductsApi/GetAllProducts
Unless you include this UrlRewrite rule in your web.config:
Thanks, I'll missed the part "Umbraco" in the URL I think, will test again and report back.
/E
Hi again,
I'am not able to make it work.
My folder structure.
ProductsApiController.cs
Trying to access the GetAllProducts method by this url: http://localhost:4635/Umbraco/api/ProductsApiController/GetAllProducts
but it just returns a 404 page.
/E
You need to leave out the 'Controller' part, like I mentioned before: /Umbraco/Api/ProductsApi/GetAllProducts
Copy paste, is a bad thing :). Also tested with http://localhost:4635/Umbraco/api/ProductsApi/GetAllProducts
Still no go. Should also mention that it's not the 404 page generated by Umbraco, is a 404 page generated from IIS.
/E
A more detailed description of the 404 page.
Detailed Error Information:
The physical path is point to MyProject\Umbraco\Api... which seems wrong.
/E
Okay, I got it to work. It may be that I misunderstood something, but for others that made the same mistake might be helped by this.
Instead of creating a folder Controllers under the root, add the controller to the App_Code instead and everything works like a charm.
Like this:
I seems that i does not matter if the ProductsApiController.cs is inside a folder as long as it's located in the App_Code folder.
This also works:
Thanks again for the help kipusoep
is working on a reply...