Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Olov 27 posts 101 karma points
    Jun 01, 2016 @ 09:42
    Olov
    0

    Url = '((Umbraco.Web.Models.PublishedContentBase)typedContent).Url' threw an exception of type 'System.InvalidOperationException'

    I have a REST API which works just as expected as long as I first visit a page after an application recycle.

    If I recycle the application and hit the API first I get an exception when trying to access the Url property on a IPublishedContent.

     Url = '((Umbraco.Web.Models.PublishedContentBase)typedContent).Url' threw an exception of type 'System.InvalidOperationException'
    

    I load the content with _umbracoHelper.TypedContent(contentId) and instantiate _umbracoContext with the following code:

    var umbracoContext = UmbracoContext.Current;
    
            if (umbracoContext == null)
            {
                var httpContext = new HttpContextWrapper(HttpContext.Current);
    
                UmbracoContext.EnsureContext(
                    httpContext,
                    ApplicationContext.Current,
                    new WebSecurity(httpContext, ApplicationContext.Current),
                    UmbracoConfig.For.UmbracoSettings(),
                    UrlProviderResolver.Current.Providers,
                    false);
            }
    
            _umbracoHelper = new UmbracoHelper(umbracoContext);
    

    What am I missing?

Please Sign in or register to post replies

Write your reply to:

Draft