Falling back to a default base URL in case none is configured.

This fixes an issue where you run Setup from a command line and the recipe does not set BaseUrl on site settings.
The issue is that if the HttpContext does not have a URL, certain properties on the Request object will throw when constructing a URI with a null value.
This commit is contained in:
Sipke Schoorstra
2015-07-24 10:34:37 +01:00
parent c0ebbd4ce7
commit ea91185816

View File

@@ -21,7 +21,8 @@ namespace Orchard.Mvc {
public HttpContextBase CreateContext(ILifetimeScope lifetimeScope) {
return new MvcModule.HttpContextPlaceholder(_threadStaticContexts, _contextKey, () => {
return lifetimeScope.Resolve<ISiteService>().GetSiteSettings().BaseUrl;
var baseUrl = lifetimeScope.Resolve<ISiteService>().GetSiteSettings().BaseUrl;
return !String.IsNullOrEmpty(baseUrl) ? baseUrl : "http://localhost"; // Return a valid URL always.
});
}