Exception on Macros, Rich Text Editors and API controllers
Hi,
I'm experiencing a problem when using models generated by API Models builder within an UmbracoAPIController.
My controller I've simplified and have got this:
public class CoursesController : UmbracoApiController
{
[AcceptVerbs("GET")]
[HttpGet]
public HttpResponseMessage GetBody()
{
Guid guId = new Guid("176f0be4-4d59-4868-b4d7-9320d43d9311");
CourseSlide courseTextCard = (CourseSlide) UmbracoContext.ContentCache.GetById(1197);
HttpContext.Current.Response.Write(courseTextCard.Introduction);
return new HttpResponseMessage();
}
}
Where CourseSlide is the model generated by models builder and Introduction is rich text editor field. This all works OK until I have a Macro within the rich text editor and then I got the following exception:
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Cannot render a macro when there is no current PublishedContentRequest.
</ExceptionMessage>
<ExceptionType>System.InvalidOperationException</ExceptionType>
<StackTrace>
at Umbraco.Web.UmbracoComponentRenderer.RenderMacro(String alias, IDictionary`2 parameters) at Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.<>c__DisplayClass0_1.<RenderRteMacros>b__1(String macroAlias, Dictionary`2 macroAttributes) at Umbraco.Core.Macros.MacroTagParser.ParseMacros(String text, Action`1 textFoundCallback, Action`2 macroFoundCallback) at Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.RenderRteMacros(String source, Boolean preview) at Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.ConvertDataToSource(PublishedPropertyType propertyType, Object source, Boolean preview) at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.get_Value() at Umbraco.Web.PublishedPropertyExtension.GetValue[T](IPublishedProperty property, Boolean withDefaultValue, T defaultValue) at Umbraco.Web.PublishedContentExtensions.GetPropertyValue[T](IPublishedContent content, String alias, Boolean recurse, Boolean withDefaultValue, T defaultValue) at Umbraco.Web.PublishedContentExtensions.GetPropertyValue[T](IPublishedContent content, String alias) at papaa_models.CourseSlide.get_Introduction() in D:\Development\Nemisys\Projects\papaa-website\source\papaa-models\CourseSlide.generated.cs:line 63 at elearning_module.Controllers.CoursesController.GetBody() in D:\Development\Nemisys\Projects\papaa-website\source\elearning-module\Controllers\CourseApiController.cs:line 225 at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
</StackTrace>
</Error>
This is suggesting a missing PubslishedContentRequest but I'm not sure how to get around this on an API Controller?
Exception on Macros, Rich Text Editors and API controllers
Hi,
I'm experiencing a problem when using models generated by API Models builder within an UmbracoAPIController.
My controller I've simplified and have got this:
Where CourseSlide is the model generated by models builder and Introduction is rich text editor field. This all works OK until I have a Macro within the rich text editor and then I got the following exception:
This is suggesting a missing PubslishedContentRequest but I'm not sure how to get around this on an API Controller?
Any help would be appreciated.
Thanks Andy
Hi,
Managed to find a solution to this by creating my own PublishedContentRequest and assigning to the Umbraco Context based on https://our.umbraco.com/forum/developers/extending-umbraco/74940-cannot-render-a-macro-when-there-is-no-current-publishedcontentrequest-custom-controllermodel.
Thanks Andy
is working on a reply...