-1

I am using Umbraco 7.4.0. When I installed Umbraco Forms 4.2.1 in my project that working fine.when i was proceeding a project, i need to use webapi to get user registration info, but i can't receive data from webapi on Umbraco. But if i copy code to another page outside Umbraco, i can receive that data from webapi. Here is the partial

I tried to revise the script, deleted some useless script, but the problem is still there. I want to know why is it like this? Am I missing something? Any help would be greatly appreciated.

eric
  • 1
  • 2

1 Answers1

0

It's a bit hard to answer your question without more information on what you are trying to do.

You should however note that if you just copy a controller class from a normal ASP.NET project into a Umbraco solution it will not "just work".

Controllers routes needs to be registrered for controller actions to be hit. This usually happens by auto-routing on /controller/action/id URLs in your site for MVC and /api/controller/id for WebAPI controllers.

This auto-routing is not enabled by default in a Umbraco site so you would have to manually do something similar to what happens in the RouteConfig.cs / WebApiConfig.cs to route controllers and be able to reach them.

You should however also look into using the UmbracoApiController which will most likely be the easiest solution for you. If you make your controller inherit from this, it will get auto-routed by Umbraco on a /Umbraco/Api/[YourControllerName] URL and you should be able to reach it. The cool thing about using the UmbracoApiController is that it is just the same as a normal WebAPI controller, with the added benefit of being able to reach the Umbraco context/services.

You can see documentation on the webapi/routing stuff here: https://our.umbraco.org/documentation/reference/routing/webapi/

Claus
  • 1,975
  • 18
  • 24