#21391: Fixed layout and shape rendering from background processes.

This commit is contained in:
Sipke Schoorstra
2015-04-13 15:44:40 +02:00
parent 920819544a
commit 840aea5ff0
4 changed files with 56 additions and 15 deletions
@@ -109,9 +109,9 @@ namespace Orchard.Layouts.Services {
private void BindPlacement(BuildShapeContext context, string displayType, string stereotype) {
context.FindPlacement = (partShapeType, differentiator, defaultLocation) => {
var workContext = _workContextAccessor.GetContext(_requestContext.HttpContext);
var theme = workContext.CurrentTheme;
var shapeTable = _shapeTableLocator.Value.Lookup(theme.Id);
var request = _requestContext.HttpContext.Request;
var shapeTable = workContext.HttpContext != null
? _shapeTableLocator.Value.Lookup(workContext.CurrentTheme.Id)
: _shapeTableLocator.Value.Lookup(null);
ShapeDescriptor descriptor;
if (shapeTable.Descriptors.TryGetValue(partShapeType, out descriptor)) {
@@ -154,8 +154,7 @@ namespace Orchard.ContentManagement {
/// <summary>
/// Gets the current app-relative path, i.e. ~/my-blog/foo.
/// </summary>
private string GetPath()
{
private string GetPath() {
return VirtualPathUtility.AppendTrailingSlash(_virtualPathProvider.ToAppRelative(_requestContext.HttpContext.Request.Path));
}
}
@@ -169,6 +169,8 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
context.ViewContext.ViewData = new ViewDataDictionary(context.Value);
context.ViewContext.TempData = new TempDataDictionary();
context.ViewContext.View = viewResult.View;
context.ViewContext.RouteData = controllerContext.RouteData;
context.ViewContext.RequestContext.RouteData = controllerContext.RouteData;
viewResult.View.Render(context.ViewContext, sw);
viewResult.ViewEngine.ReleaseView(controllerContext, viewResult.View);
return new HtmlString(sw.GetStringBuilder().ToString());
+42 -2
View File
@@ -83,7 +83,7 @@ namespace Orchard.Mvc {
}
/// <summary>
/// standin context for background tasks.
/// Standin context for background tasks.
/// </summary>
class HttpContextPlaceholder : HttpContextBase {
private readonly Lazy<string> _baseUrl;
@@ -124,6 +124,12 @@ namespace Orchard.Mvc {
public override string ApplyAppPathModifier(string virtualPath) {
return virtualPath;
}
public override HttpCookieCollection Cookies {
get {
return new HttpCookieCollection();
}
}
}
/// <summary>
@@ -158,7 +164,7 @@ namespace Orchard.Mvc {
public override NameValueCollection Headers {
get {
return new NameValueCollection {{"Host", _uri.Authority}};
return new NameValueCollection { { "Host", _uri.Authority } };
}
}
@@ -184,10 +190,44 @@ namespace Orchard.Mvc {
}
}
public override HttpCookieCollection Cookies {
get {
return new HttpCookieCollection();
}
}
public override bool IsLocal {
get { return true; }
}
public override string Path {
get { return "/"; }
}
public override string UserAgent {
get {
return "Placeholder";
}
}
public override HttpBrowserCapabilitiesBase Browser {
get {
return new HttpBrowserCapabilitiesPlaceholder();
}
}
}
class HttpBrowserCapabilitiesPlaceholder : HttpBrowserCapabilitiesBase {
public override string this[string key] {
get {
return "";
}
}
public override bool IsMobileDevice { get { return false; } }
public override string Browser { get { return "Placeholder"; } }
public override bool Cookies { get { return true; } }
public override ArrayList Browsers { get { return new ArrayList(); } }
}
}
}