Copied to clipboard

Flag this post as spam?

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


  • Thomas Heinrich-Linke 3 posts 23 karma points
    Feb 21, 2014 @ 10:27
    Thomas Heinrich-Linke
    0

    Umbraco MVC5 Backend WebApi

    My client wants an existing project included into his Umbraco Website, with Umbraco running as the "parent" application and the other project running in an area. This is necessary since there is only one domain available and the Umbraco site has to display content from the other project.

    Unfortunately the other project demands MVC5/WebApi2.

    What I did was get the Umbraco (7.0.3) source code and follow the "official" instructions to port it to MVC5. I did not update all nuget packages since that lead to a staggering amount of problems. I had to compile ClientDependency.Core.Mvc against MVC5 on my own to make things work and to replace the FixedRazorViewEngine with the normal RazorViewEngine. At this point I could run the installer.

    The next problem crept up in the backend. Loading the trees gave me an exception in lines like this

    // \Umbraco.Web\Trees\ApplicationTreeExtensions.cs

    instance.Request = controllerContext.Request;

    This leads on an InvalidOperationException "The request context property on the request must be null or match ApiController.RequestContext". Googling this wasn't very helpful, except this seems to be a changed behaviour in WebApi2 and is "by design" and "to simplify things" (huh?), but it's not even listed in breaking changes.

    What I did to get it running was the following:

    var rContext = controllerContext.Request.GetRequestContext(); // preserve context
    controllerContext.Request.SetRequestContext(instance.RequestContext); // prevent exception
    instance.Request = controllerContext.Request; // now it works, yay

    // now restore the original values over the original values
    instance.RequestContext.ClientCertificate = rContext.ClientCertificate;
    instance.RequestContext.Url = rContext.Url;
    instance.RequestContext.VirtualPathRoot = rContext.VirtualPathRoot;

    What I want to know:
    1) Is this the right way to go? (instance.RequestContact is readonly btw.).
    2) I now have a (seemingly) working backend and a (very basic) Hello World site running. Has anyone tried to do what I did before and knows of further problems down the road?
    Thanks for your patience,
    Tom
  • Paul Stoker 39 posts 72 karma points c-trib
    Feb 28, 2014 @ 16:55
    Paul Stoker
    0

    Hi Thomas, personally, rather than hacking into Umbraco to port it, I'd just put the child project under a virtual directory as below:

    umbracoparentsite.com - Website

    umbracoparentsite.com/project - Virtual Directory

  • Thomas Heinrich-Linke 3 posts 23 karma points
    Mar 10, 2014 @ 10:49
    Thomas Heinrich-Linke
    0

    Hi Paul,

    thanks for your reply. Unfortunately this is not possible in this case. I need to render Partial Actions from the child project into Umbraco views and vice versa. And I don't want to use IFrames. Also I need to unify login procedures and other session related stuff.

     

    Kind regards,

    Tom

     

    PS: sorry for replying so late, somehow I missed the notification.

  • Karl Kopp 121 posts 227 karma points
    Nov 26, 2014 @ 09:08
    Karl Kopp
    0

    Did u end up getting a resolution to this???

Please Sign in or register to post replies

Write your reply to:

Draft