Copied to clipboard

Flag this post as spam?

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


  • Thomas Andersen 2 posts 22 karma points
    Mar 16, 2015 @ 11:20
    Thomas Andersen
    0

    UmbracoContext null

    Hi guys'n'girls.

    Been working on an mvc controller with an endpoint that will return xml to the requesting client.

    My controllers code looks like this:

        [PluginController("Foo")]

        public class FeedController : UmbracoController

        {

            public FeedController() : base(UmbracoContext.EnsureContext(new HttpContextWrapper(System.Web.HttpContext.Current), ApplicationContext.Current, new WebSecurity(new HttpContextWrapper(System.Web.HttpContext.Current), ApplicationContext.Current), true))

            {

     

            }

     

            [System.Web.Http.HttpGet]

            public XmlActionResult Publish()

            {

                var document = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),

                    new XElement("count", 10));

     

                return new XmlActionResult(document);

            }

        }

     

    and i've created a custom application event handler that looks like this:

     public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)

            {

                RouteTable.Routes.MapRoute("Feed", "feed.xml", new { controller = "Feed", action = "Publish" });

            }

     

    and when I run my Umbraco site in Microsoft Visual Studio and request the url http://localhost:<port>/feed.xml it returns the expected xml to me.

    So here is my problem: 

    I want to create the controller and the custom application event handler into a package so I can import my features into another custom umbraco solution.

    When I created the package and import it into another solution I see that my two files is installed correctly but when i try to enter http://domain.tld/feed.xml I get following error:

    Value cannot be null.

    Parameter name: umbracoContext

     

    Notice that I've tried to hack this by re-building the umbraco context in the controller ctor.

    So if I take the now "not-included" controller and include it into visual studio again it works.

    Any ideas ?

     

    Thanks

     

    Btw - using umbraco v. 7

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Mar 16, 2015 @ 12:06
    Jeroen Breuer
    0

    Hello,

    Are you inheriting from the correct controller? Did you try the Umbraco Web API?

    Jeroen

  • Thomas Andersen 2 posts 22 karma points
    Mar 16, 2015 @ 12:10
    Thomas Andersen
    0

    Hi Jeroen:

    I'm using the umbracocontroller otherwise if I use the web api controller my umbracocontext issue will be permanent.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies