In a scope of Sitecore Web project an API Contoller is used. Got the following response error message during jQuery AJAX GET API request:
On a back-end side I use IHttpActionResult action method that returns Json object such as return Json(model).
An API Action method looks like below:
public IHttpActionResult Get(Guid id)
{
var targetItem = Context.Database.GetItem(new ID(id)); var model = new List<T>();
//business logic where appropriate data<T> (simple properties such as Guid, string) is added to model.
return Json(model);
}
and AJAX call function looks like below:
$.ajax({
type: "GET",
url: url,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(response) { },
error (req,err){ //here I got "parsererror" message }
}
During this call the following Exception is executed:
Exception: System.InvalidOperationException Message: Attempt to retrieve context object of type 'Sitecore.Mvc.Presentation.PageContext' from empty stack. Source: Sitecore.Mvc at Sitecore.Mvc.Common.ContextService.Peek[T]() at Sitecore.Mvc.Pipelines.MvcPipelineArgs.get_PageContext() at Sitecore.Mvc.ExperienceEditor.Pipelines.Request.RequestEnd.AddPageExtenders.Process(RequestEndArgs args)
This issue is caused on Production CD server. In localhost everything is OK. Any ideas how I can avoid this issue?
public IHttpActionResult Get(Guid id) { var targetItem = Context.Database.GetItem(new ID(id)); var model = new List<T>(); //business logic where appropriate data<T> (simple properties such as Guid, string) is added to model. return Json(model); }
$.ajax({ type: "GET", url: url, dataType: "json", contentType: "application/json; charset=utf-8", success: function(response) { }, error (req,err){ //here I got parsererror message }
Exception: System.InvalidOperationException Message: Attempt to retrieve context object of type 'Sitecore.Mvc.Presentation.PageContext' from empty stack. Source: Sitecore.Mvc at Sitecore.Mvc.Common.ContextService.Peek[T]() at Sitecore.Mvc.Pipelines.MvcPipelineArgs.get_PageContext() at Sitecore.Mvc.ExperienceEditor.Pipelines.Request.RequestEnd.AddPageExtenders.Process(RequestEndArgs args)