Copied to clipboard

Flag this post as spam?

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


  • Petr Svoboda 17 posts 68 karma points
    Mar 03, 2015 @ 11:01
    Petr Svoboda
    0

    Problem with UmbracoContext.Current

    Hello,

    I connect to Umbraco CMS by core Umbraco libraries from external application. And I have problem, Umbraco.Web.UmbracoContext.Current is null.

    I create new context by UmbracoContext.EnsureContext, but this couses exception (Current has not been initialized on Umbraco.Web.Routing.UrlProviderResolver. You must initialize Current before trying to read it.):

    UmbracoContext umbracoContext = 
        UmbracoContext.EnsureContext(
            new HttpContextWrapper(System.Web.HttpContext.Current),
            ApplicationContext.Current,
            new WebSecurity(new HttpContextWrapper(System.Web.HttpContext.Current), ApplicationContext.Current),
            false);
    var urlProvider = umbracoContext.UrlProvider;

    This code couses exception too (An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code, additional information: Current has not been initialized on Umbraco.Web.PublishedCache.PublishedCachesResolver. You must initialize Current before trying to read it.):

    UmbracoContext umbracoContext = 
        UmbracoContext.EnsureContext(
            new HttpContextWrapper(System.Web.HttpContext.Current),
            ApplicationContext.Current,
            new WebSecurity(new HttpContextWrapper(System.Web.HttpContext.Current), ApplicationContext.Current),
            false);
    UmbracoHelper umbracoHelper = new UmbracoHelper(umbracoContext);
    var image = umbracoHelper.Media(id);
    
    Please help me, thanks Petr
  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 03, 2015 @ 12:05
    Jeroen Breuer
    0

    Hello,

    This Umbraco console app might be able to help. It also uses the API outside of a default Umbraco environment: https://github.com/sitereactor/umbraco-console-example

    Jeroen

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 03, 2015 @ 12:20
    Ismail Mayat
    1

    Petr,

    See https://github.com/Isle-Of-Man-Government/IOMG.Umbraco.StandaloneServices this project shows you how to use umbraco in your own external application.

    Regards

    Ismail

  • Petr Svoboda 17 posts 68 karma points
    Mar 03, 2015 @ 13:35
    Petr Svoboda
    0

    Thanks. I test both ( https://github.com/sitereactor/umbraco-console-example and  https://github.com/Isle-Of-Man-Government/IOMG.Umbraco.StandaloneServices) without success.

     

    Notice:

    Directly in Umbraco CMS project this work ok.

    It don't work only when I connect to Umbraco CMS by Core Umbraco libraries from external application.

Please Sign in or register to post replies

Write your reply to:

Draft