mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Fixed a potential "ValueFactory attempted to access the Value property of this instance" issue.
The underlying cause of such an error is a recursive call issue, where some code in a background task accesses the current http context (which is a stand in), while its construction also (indirectly) accesses the http context in order to get the site content item and query the configured BaseUrl. In theory we could access this information straight from the database without loading the Site content item, but since the URL value doesn't really matter it is better to keep it simple.
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Collections.Concurrent;
|
||||
using System.Web;
|
||||
using Autofac;
|
||||
using Orchard.Mvc.Extensions;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Mvc {
|
||||
public class HttpContextAccessor : IHttpContextAccessor {
|
||||
@@ -20,10 +19,11 @@ namespace Orchard.Mvc {
|
||||
}
|
||||
|
||||
public HttpContextBase CreateContext(ILifetimeScope lifetimeScope) {
|
||||
return new MvcModule.HttpContextPlaceholder(_threadStaticContexts, _contextKey, () => {
|
||||
var baseUrl = lifetimeScope.Resolve<ISiteService>().GetSiteSettings().BaseUrl;
|
||||
return !String.IsNullOrEmpty(baseUrl) ? baseUrl : "http://localhost"; // Return a valid URL always.
|
||||
});
|
||||
return new MvcModule.HttpContextPlaceholder(
|
||||
_threadStaticContexts,
|
||||
_contextKey,
|
||||
() => "http://localhost" // Use a valid URL always for the fake request. The value itself doesn't matter.
|
||||
);
|
||||
}
|
||||
|
||||
private HttpContextBase GetContext() {
|
||||
|
Reference in New Issue
Block a user