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
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 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.
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;
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
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.
Did u end up getting a resolution to this???
is working on a reply...