The ajax is not hitting. The request skips getJson call and returns undefined response.
This is my api controller method:
public class ProductController : ApiController {
// GET api/<controller>
public IEnumerable<ProductModel> ProductList()
{
ProductSearcher searcher = new ProductSearcher();
return searcher.GetResults();
}
}
In the config I have defined:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Postman returns Object reference not set to an instance of an object but it doesn't even hit the ProductList either.
I have selected to run multiple projects - my app start project and web api project.
This is the error stacktrace - it looks to me like umbraco does looks for routing while I need to route to non-umbraco api:
[NullReferenceException: Object reference not set to an instance of an object.]
Umbraco.Web.Routing.ContentLastChanceFinderByNotFoundHandlers.HandlePageNotFound(PublishedContentRequest docRequest) +152
Umbraco.Web.Routing.ContentLastChanceFinderByNotFoundHandlers.TryFindContent(PublishedContentRequest docRequest) +10
Umbraco.Web.Routing.PublishedContentRequestEngine.HandlePublishedContent() +529
Umbraco.Web.Routing.PublishedContentRequestEngine.FindPublishedContentAndTemplate() +250
Umbraco.Web.Routing.PublishedContentRequestEngine.PrepareRequest() +107
Umbraco.Web.UmbracoModule.ProcessRequest(HttpContextBase httpContext) +361
Umbraco.Web.UmbracoModule.<Init>b__8(Object sender, EventArgs e) +80
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +71
Thanks suman but this is not a solution, I don't use umbraco api and I won't in this project so there is no reason to load the whole bunch of umbraco dependencies just to perform a get on the other project.
I am unable to hit Get method in WebAP
I have WebAPI2 project in my solution where I;m using umbraco 7 as a startup project.
I have trouble to hit webapi action. I am getting 500 error in the console and the api is not reached.
This is my ajax call:
The ajax is not hitting. The request skips getJson call and returns undefined response.
This is my api controller method:
In the config I have defined:
Postman returns Object reference not set to an instance of an object but it doesn't even hit the ProductList either.
I have selected to run multiple projects - my app start project and web api project.
This is the error stacktrace - it looks to me like umbraco does looks for routing while I need to route to non-umbraco api:
Hi there
Is it worth updating the umbracoReservedPaths in the appSettings in the web.config with your base url ?
Cheers
Nigel
It might have worked as the change to api routing made a difference (see my reply below), I'll check this. Thanks
Manila,
Apologies as I'm not 100% sure this will help but in the code snippets you showed:
but then in the API controller, you're asking for
While you've not shown the rest of your code, and that's fine - are you 100% sure you're trying to hit the right endpoint?
Happy to chat, look forward to your response!
Kind regards, Jon
Hi, The content of GetResults() is irrelevant in this moment as the containing method does not even get hit.
I have solved this by changing the api routing, seee the solution here: https://stackoverflow.com/questions/51785141/i-am-unable-to-hit-get-method-in-webapi-with-umbraco-project
Although I'm struggling to get the response on the ks site in my project. It displays well in the webapi template though so the api method is working, I just have no idea while the response is not passed through to the calling project, see the other thread: https://stackoverflow.com/questions/51792538/ajax-call-to-webapi-does-not-hit-the-ajax-response-and-not-returning-results
Hi Manila,
Can you try this,
Your controller should inherit from "UmbracoApiController". And your $.getJSON("umbraco/api/Product")
Thanks suman but this is not a solution, I don't use umbraco api and I won't in this project so there is no reason to load the whole bunch of umbraco dependencies just to perform a get on the other project.
is working on a reply...