Merge branch 'netcore/feature/move-files-after-umbraco-context-abstractions' into netcore/feature/move-mappings-after-httpcontext

This commit is contained in:
Bjarke Berg
2020-02-17 13:23:02 +01:00
66 changed files with 243 additions and 201 deletions
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Composing;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Web;
@@ -146,6 +148,14 @@ namespace Umbraco.Core
return template == null ? string.Empty : template.Alias;
}
public static bool IsAllowedTemplate(this IPublishedContent content, IContentTypeService contentTypeService,
IUmbracoSettingsSection umbracoSettingsSection, int templateId)
{
return content.IsAllowedTemplate(contentTypeService,
umbracoSettingsSection.WebRouting.DisableAlternativeTemplates,
umbracoSettingsSection.WebRouting.ValidateAlternativeTemplates, templateId);
}
public static bool IsAllowedTemplate(this IPublishedContent content, IContentTypeService contentTypeService, bool disableAlternativeTemplates, bool validateAlternativeTemplates, int templateId)
{
if (disableAlternativeTemplates)
@@ -17,12 +17,16 @@ namespace Umbraco.Web.Routing
private readonly IRequestHandlerSection _requestConfig;
private readonly ISiteDomainHelper _siteDomainHelper;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly UriUtility _uriUtility;
private readonly IPublishedValueFallback _publishedValueFallback;
public AliasUrlProvider(IGlobalSettings globalSettings, IRequestHandlerSection requestConfig, ISiteDomainHelper siteDomainHelper, IUmbracoContextAccessor umbracoContextAccessor)
public AliasUrlProvider(IGlobalSettings globalSettings, IRequestHandlerSection requestConfig, ISiteDomainHelper siteDomainHelper, UriUtility uriUtility, IPublishedValueFallback publishedValueFallback, IUmbracoContextAccessor umbracoContextAccessor)
{
_globalSettings = globalSettings;
_requestConfig = requestConfig;
_siteDomainHelper = siteDomainHelper;
_uriUtility = uriUtility;
_publishedValueFallback = publishedValueFallback;
_umbracoContextAccessor = umbracoContextAccessor;
}
@@ -86,7 +90,7 @@ namespace Umbraco.Web.Routing
if (varies)
yield break;
var umbracoUrlName = node.Value<string>(Constants.Conventions.Content.UrlAlias);
var umbracoUrlName = node.Value<string>(_publishedValueFallback, Constants.Conventions.Content.UrlAlias);
var aliases = umbracoUrlName?.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (aliases == null || aliases.Any() == false)
@@ -96,7 +100,7 @@ namespace Umbraco.Web.Routing
{
var path = "/" + alias;
var uri = new Uri(path, UriKind.Relative);
yield return UrlInfo.Url(UriUtility.UriFromUmbraco(uri, _globalSettings, _requestConfig).ToString());
yield return UrlInfo.Url(_uriUtility.UriFromUmbraco(uri, _globalSettings, _requestConfig).ToString());
}
}
else
@@ -111,8 +115,8 @@ namespace Umbraco.Web.Routing
if (varies && !node.HasCulture(domainUri.Culture.Name)) continue;
var umbracoUrlName = varies
? node.Value<string>(Constants.Conventions.Content.UrlAlias, culture: domainUri.Culture.Name)
: node.Value<string>(Constants.Conventions.Content.UrlAlias);
? node.Value<string>(_publishedValueFallback,Constants.Conventions.Content.UrlAlias, culture: domainUri.Culture.Name)
: node.Value<string>(_publishedValueFallback, Constants.Conventions.Content.UrlAlias);
var aliases = umbracoUrlName?.Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries);
@@ -123,7 +127,7 @@ namespace Umbraco.Web.Routing
{
var path = "/" + alias;
var uri = new Uri(CombinePaths(domainUri.Uri.GetLeftPart(UriPartial.Path), path));
yield return UrlInfo.Url(UriUtility.UriFromUmbraco(uri, _globalSettings, _requestConfig).ToString(), domainUri.Culture.Name);
yield return UrlInfo.Url(_uriUtility.UriFromUmbraco(uri, _globalSettings, _requestConfig).ToString(), domainUri.Culture.Name);
}
}
}
@@ -17,11 +17,13 @@ namespace Umbraco.Web.Routing
{
private readonly IRedirectUrlService _redirectUrlService;
private readonly ILogger _logger;
private readonly IPublishedUrlProvider _publishedUrlProvider;
public ContentFinderByRedirectUrl(IRedirectUrlService redirectUrlService, ILogger logger)
public ContentFinderByRedirectUrl(IRedirectUrlService redirectUrlService, ILogger logger, IPublishedUrlProvider publishedUrlProvider)
{
_redirectUrlService = redirectUrlService;
_logger = logger;
_publishedUrlProvider = publishedUrlProvider;
}
/// <summary>
@@ -45,7 +47,7 @@ namespace Umbraco.Web.Routing
}
var content = frequest.UmbracoContext.Content.GetById(redirectUrl.ContentId);
var url = content == null ? "#" : content.Url(redirectUrl.Culture);
var url = content == null ? "#" : content.Url(_publishedUrlProvider, redirectUrl.Culture);
if (url.StartsWith("#"))
{
_logger.Debug<ContentFinderByRedirectUrl>("Route {Route} matches content {ContentId} which has no url.", route, redirectUrl.ContentId);
@@ -18,10 +18,14 @@ namespace Umbraco.Web.Routing
/// </remarks>
public class ContentFinderByUrlAlias : IContentFinder
{
private readonly IPublishedValueFallback _publishedValueFallback;
private readonly IVariationContextAccessor _variationContextAccessor;
protected ILogger Logger { get; }
public ContentFinderByUrlAlias(ILogger logger)
public ContentFinderByUrlAlias(ILogger logger, IPublishedValueFallback publishedValueFallback, IVariationContextAccessor variationContextAccessor)
{
_publishedValueFallback = publishedValueFallback;
_variationContextAccessor = variationContextAccessor;
Logger = logger;
}
@@ -51,7 +55,7 @@ namespace Umbraco.Web.Routing
return node != null;
}
private static IPublishedContent FindContentByAlias(IPublishedContentCache cache, int rootNodeId, string culture, string alias)
private IPublishedContent FindContentByAlias(IPublishedContentCache cache, int rootNodeId, string culture, string alias)
{
if (alias == null) throw new ArgumentNullException(nameof(alias));
@@ -84,11 +88,11 @@ namespace Umbraco.Web.Routing
if (varies)
{
if (!c.HasCulture(culture)) return false;
v = c.Value<string>(propertyAlias, culture);
v = c.Value<string>(_publishedValueFallback, propertyAlias, culture);
}
else
{
v = c.Value<string>(propertyAlias);
v = c.Value<string>(_publishedValueFallback, propertyAlias);
}
if (string.IsNullOrWhiteSpace(v)) return false;
v = "," + v.Replace(" ", "") + ",";
@@ -101,12 +105,12 @@ namespace Umbraco.Web.Routing
if (rootNodeId > 0)
{
var rootNode = cache.GetById(rootNodeId);
return rootNode?.Descendants().FirstOrDefault(x => IsMatch(x, test1, test2));
return rootNode?.Descendants(_variationContextAccessor).FirstOrDefault(x => IsMatch(x, test1, test2));
}
foreach (var rootContent in cache.GetAtRoot())
{
var c = rootContent.DescendantsOrSelf().FirstOrDefault(x => IsMatch(x, test1, test2));
var c = rootContent.DescendantsOrSelf(_variationContextAccessor).FirstOrDefault(x => IsMatch(x, test1, test2));
if (c != null) return c;
}
@@ -1,9 +1,7 @@
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Composing;
using Umbraco.Core.Services;
namespace Umbraco.Web.Routing
@@ -19,11 +17,15 @@ namespace Umbraco.Web.Routing
public class ContentFinderByUrlAndTemplate : ContentFinderByUrl
{
private readonly IFileService _fileService;
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
private readonly IContentTypeService _contentTypeService;
public ContentFinderByUrlAndTemplate(ILogger logger, IFileService fileService)
public ContentFinderByUrlAndTemplate(ILogger logger, IFileService fileService, IUmbracoSettingsSection umbracoSettingsSection, IContentTypeService contentTypeService)
: base(logger)
{
_fileService = fileService;
_umbracoSettingsSection = umbracoSettingsSection;
_contentTypeService = contentTypeService;
}
/// <summary>
@@ -73,7 +75,7 @@ namespace Umbraco.Web.Routing
}
// IsAllowedTemplate deals both with DisableAlternativeTemplates and ValidateAlternativeTemplates settings
if (!node.IsAllowedTemplate(template.Id))
if (!node.IsAllowedTemplate(_contentTypeService, _umbracoSettingsSection, template.Id))
{
Logger.Warn<ContentFinderByUrlAndTemplate>("Alternative template '{TemplateAlias}' is not allowed on node {NodeId}.", template.Alias, node.Id);
frequest.PublishedContent = null; // clear
@@ -1,5 +1,4 @@
using System;
using Umbraco.Core.Composing;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
@@ -10,11 +9,13 @@ namespace Umbraco.Web.Routing
/// </summary>
public class DefaultMediaUrlProvider : IMediaUrlProvider
{
private readonly UriUtility _uriUtility;
private readonly Lazy<PropertyEditorCollection> _propertyEditors;
public DefaultMediaUrlProvider(Lazy<PropertyEditorCollection> propertyEditors)
public DefaultMediaUrlProvider(Lazy<PropertyEditorCollection> propertyEditors, UriUtility uriUtility)
{
_propertyEditors = propertyEditors ?? throw new ArgumentNullException(nameof(propertyEditors));
_uriUtility = uriUtility;
}
/// <inheritdoc />
@@ -70,7 +71,7 @@ namespace Umbraco.Web.Routing
throw new ArgumentOutOfRangeException(nameof(mode));
}
return UriUtility.MediaUriFromUmbraco(uri);
return _uriUtility.MediaUriFromUmbraco(uri);
}
}
}
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Logging;
@@ -18,13 +17,15 @@ namespace Umbraco.Web.Routing
private readonly IGlobalSettings _globalSettings;
private readonly ISiteDomainHelper _siteDomainHelper;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly UriUtility _uriUtility;
public DefaultUrlProvider(IRequestHandlerSection requestSettings, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, IUmbracoContextAccessor umbracoContextAccessor)
public DefaultUrlProvider(IRequestHandlerSection requestSettings, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, IUmbracoContextAccessor umbracoContextAccessor, UriUtility uriUtility)
{
_requestSettings = requestSettings;
_logger = logger;
_globalSettings = globalSettings;
_siteDomainHelper = siteDomainHelper;
_uriUtility = uriUtility;
_umbracoContextAccessor = umbracoContextAccessor;
}
@@ -112,7 +113,7 @@ namespace Umbraco.Web.Routing
var path = pos == 0 ? route : route.Substring(pos);
var uri = new Uri(CombinePaths(d.Uri.GetLeftPart(UriPartial.Path), path));
uri = UriUtility.UriFromUmbraco(uri, _globalSettings, _requestSettings);
uri = _uriUtility.UriFromUmbraco(uri, _globalSettings, _requestSettings);
yield return UrlInfo.Url(uri.ToString(), culture);
}
}
@@ -171,7 +172,7 @@ namespace Umbraco.Web.Routing
// UriFromUmbraco will handle vdir
// meaning it will add vdir into domain urls too!
return UriUtility.UriFromUmbraco(uri, _globalSettings, _requestSettings);
return _uriUtility.UriFromUmbraco(uri, _globalSettings, _requestSettings);
}
string CombinePaths(string path1, string path2)
@@ -1,6 +1,7 @@
using System;
using Umbraco.Core.Models.PublishedContent;
namespace Umbraco.Web.Routing
{
/// <summary>
@@ -2,12 +2,8 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Web;
using Umbraco.Core;
using Umbraco.Web.Composing;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Macros;
using Umbraco.Core.Configuration.UmbracoSettings;
namespace Umbraco.Web.Routing
@@ -9,8 +9,8 @@ namespace Umbraco.Web.Routing
{
public EnsureRoutableOutcome Outcome { get; private set; }
public RoutableAttemptEventArgs(EnsureRoutableOutcome reason, IUmbracoContext umbracoContext, HttpContextBase httpContext)
: base(umbracoContext, httpContext)
public RoutableAttemptEventArgs(EnsureRoutableOutcome reason, IUmbracoContext umbracoContext)
: base(umbracoContext)
{
Outcome = reason;
}
@@ -9,12 +9,10 @@ namespace Umbraco.Web.Routing
public class UmbracoRequestEventArgs : EventArgs
{
public IUmbracoContext UmbracoContext { get; private set; }
public HttpContextBase HttpContext { get; private set; }
public UmbracoRequestEventArgs(IUmbracoContext umbracoContext, HttpContextBase httpContext)
public UmbracoRequestEventArgs(IUmbracoContext umbracoContext)
{
UmbracoContext = umbracoContext;
HttpContext = httpContext;
}
}
}
@@ -4,21 +4,22 @@ using System.Web;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Hosting;
namespace Umbraco.Web
{
public static class UriUtility
public sealed class UriUtility
{
static string _appPath;
static string _appPathPrefix;
static UriUtility()
public UriUtility(IHostingEnvironment hostingEnvironment)
{
ResetAppDomainAppVirtualPath();
ResetAppDomainAppVirtualPath(hostingEnvironment);
}
// internal for unit testing only
internal static void SetAppDomainAppVirtualPath(string appPath)
internal void SetAppDomainAppVirtualPath(string appPath)
{
_appPath = appPath ?? "/";
_appPathPrefix = _appPath;
@@ -26,20 +27,20 @@ namespace Umbraco.Web
_appPathPrefix = String.Empty;
}
internal static void ResetAppDomainAppVirtualPath()
internal void ResetAppDomainAppVirtualPath(IHostingEnvironment hostingEnvironment)
{
SetAppDomainAppVirtualPath(HttpRuntime.AppDomainAppVirtualPath);
SetAppDomainAppVirtualPath(hostingEnvironment.ApplicationVirtualPath);
}
// will be "/" or "/foo"
public static string AppPath => _appPath;
public string AppPath => _appPath;
// will be "" or "/foo"
public static string AppPathPrefix => _appPathPrefix;
public string AppPathPrefix => _appPathPrefix;
// adds the virtual directory if any
// see also VirtualPathUtility.ToAbsolute
public static string ToAbsolute(string url)
public string ToAbsolute(string url)
{
//return ResolveUrl(url);
url = url.TrimStart('~');
@@ -48,7 +49,7 @@ namespace Umbraco.Web
// strips the virtual directory if any
// see also VirtualPathUtility.ToAppRelative
public static string ToAppRelative(string virtualPath)
public string ToAppRelative(string virtualPath)
{
if (virtualPath.InvariantStartsWith(_appPathPrefix)
&& (virtualPath.Length == _appPathPrefix.Length || virtualPath[_appPathPrefix.Length] == '/'))
@@ -60,7 +61,7 @@ namespace Umbraco.Web
// maps an internal umbraco uri to a public uri
// ie with virtual directory, .aspx if required...
public static Uri UriFromUmbraco(Uri uri, IGlobalSettings globalSettings, IRequestHandlerSection requestConfig)
public Uri UriFromUmbraco(Uri uri, IGlobalSettings globalSettings, IRequestHandlerSection requestConfig)
{
var path = uri.GetSafeAbsolutePath();
@@ -74,7 +75,7 @@ namespace Umbraco.Web
// maps a media umbraco uri to a public uri
// ie with virtual directory - that is all for media
public static Uri MediaUriFromUmbraco(Uri uri)
public Uri MediaUriFromUmbraco(Uri uri)
{
var path = uri.GetSafeAbsolutePath();
path = ToAbsolute(path);
@@ -83,7 +84,7 @@ namespace Umbraco.Web
// maps a public uri to an internal umbraco uri
// ie no virtual directory, no .aspx, lowercase...
public static Uri UriToUmbraco(Uri uri)
public Uri UriToUmbraco(Uri uri)
{
// note: no need to decode uri here because we're returning a uri
// so it will be re-encoded anyway
@@ -120,7 +121,7 @@ namespace Umbraco.Web
// ResolveUrl("page2.aspx") returns "/page2.aspx"
// Page.ResolveUrl("page2.aspx") returns "/sub/page2.aspx" (relative...)
//
public static string ResolveUrl(string relativeUrl)
public string ResolveUrl(string relativeUrl)
{
if (relativeUrl == null) throw new ArgumentNullException("relativeUrl");
@@ -182,21 +183,22 @@ namespace Umbraco.Web
/// Returns an full url with the host, port, etc...
/// </summary>
/// <param name="absolutePath">An absolute path (i.e. starts with a '/' )</param>
/// <param name="httpContext"> </param>
/// <param name="curentRequestUrl"> </param>
/// <returns></returns>
/// <remarks>
/// Based on http://stackoverflow.com/questions/3681052/get-absolute-url-from-relative-path-refactored-method
/// </remarks>
internal static Uri ToFullUrl(string absolutePath, HttpContextBase httpContext)
internal Uri ToFullUrl(string absolutePath, Uri curentRequestUrl)
{
if (httpContext == null) throw new ArgumentNullException("httpContext");
if (string.IsNullOrEmpty(absolutePath))
throw new ArgumentNullException("absolutePath");
throw new ArgumentNullException(nameof(absolutePath));
if (!absolutePath.StartsWith("/"))
throw new FormatException("The absolutePath specified does not start with a '/'");
return new Uri(absolutePath, UriKind.Relative).MakeAbsolute(httpContext.Request.Url);
return new Uri(absolutePath, UriKind.Relative).MakeAbsolute(curentRequestUrl);
}
}
}
@@ -23,7 +23,8 @@ namespace Umbraco.Web.Routing
/// <param name="urlProviders">The list of url providers.</param>
/// <param name="mediaUrlProviders">The list of media url providers.</param>
/// <param name="variationContextAccessor">The current variation accessor.</param>
public UrlProvider(Lazy<IUmbracoContextAccessor> umbracoContextAccessor, IWebRoutingSection routingSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IVariationContextAccessor variationContextAccessor)
/// <param name="propertyEditorCollection"></param>
public UrlProvider(IUmbracoContextAccessor umbracoContextAccessor, IWebRoutingSection routingSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IVariationContextAccessor variationContextAccessor)
{
if (routingSettings == null) throw new ArgumentNullException(nameof(routingSettings));
@@ -41,7 +42,7 @@ namespace Umbraco.Web.Routing
}
private readonly Lazy<IUmbracoContextAccessor> _umbracoContextAccessor;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IEnumerable<IUrlProvider> _urlProviders;
private readonly IEnumerable<IMediaUrlProvider> _mediaUrlProviders;
private readonly IVariationContextAccessor _variationContextAccessor;
@@ -55,9 +56,9 @@ namespace Umbraco.Web.Routing
#region GetUrl
private IPublishedContent GetDocument(int id) => _umbracoContextAccessor.Value.UmbracoContext.Content.GetById(id);
private IPublishedContent GetDocument(Guid id) => _umbracoContextAccessor.Value.UmbracoContext.Content.GetById(id);
private IPublishedContent GetMedia(Guid id) => _umbracoContextAccessor.Value.UmbracoContext.Media.GetById(id);
private IPublishedContent GetDocument(int id) => _umbracoContextAccessor.UmbracoContext.Content.GetById(id);
private IPublishedContent GetDocument(Guid id) => _umbracoContextAccessor.UmbracoContext.Content.GetById(id);
private IPublishedContent GetMedia(Guid id) => _umbracoContextAccessor.UmbracoContext.Media.GetById(id);
/// <summary>
/// Gets the url of a published content.
@@ -113,7 +114,7 @@ namespace Umbraco.Web.Routing
}
if (current == null)
current = _umbracoContextAccessor.Value.UmbracoContext.CleanedUmbracoUrl;
current = _umbracoContextAccessor.UmbracoContext.CleanedUmbracoUrl;
var url = _urlProviders.Select(provider => provider.GetUrl(content, mode, culture, current))
.FirstOrDefault(u => u != null);
@@ -125,7 +126,7 @@ namespace Umbraco.Web.Routing
var provider = _urlProviders.OfType<DefaultUrlProvider>().FirstOrDefault();
var url = provider == null
? route // what else?
: provider.GetUrlFromRoute(route, _umbracoContextAccessor.Value.UmbracoContext, id, _umbracoContextAccessor.Value.UmbracoContext.CleanedUmbracoUrl, Mode, culture)?.Text;
: provider.GetUrlFromRoute(route, _umbracoContextAccessor.UmbracoContext, id, _umbracoContextAccessor.UmbracoContext.CleanedUmbracoUrl, Mode, culture)?.Text;
return url ?? "#";
}
@@ -145,7 +146,7 @@ namespace Umbraco.Web.Routing
/// </remarks>
public IEnumerable<UrlInfo> GetOtherUrls(int id)
{
return GetOtherUrls(id, _umbracoContextAccessor.Value.UmbracoContext.CleanedUmbracoUrl);
return GetOtherUrls(id, _umbracoContextAccessor.UmbracoContext.CleanedUmbracoUrl);
}
/// <summary>
@@ -214,7 +215,7 @@ namespace Umbraco.Web.Routing
}
if (current == null)
current = _umbracoContextAccessor.Value.UmbracoContext.CleanedUmbracoUrl;
current = _umbracoContextAccessor.UmbracoContext.CleanedUmbracoUrl;
var url = _mediaUrlProviders.Select(provider =>
provider.GetMediaUrl(content, propertyAlias, mode, culture, current))
@@ -26,6 +26,7 @@ namespace Umbraco.Web.Routing
IContentService contentService,
IVariationContextAccessor variationContextAccessor,
ILogger logger,
UriUtility uriUtility,
IPublishedUrlProvider publishedUrlProvider)
{
if (content == null) throw new ArgumentNullException(nameof(content));
@@ -36,6 +37,7 @@ namespace Umbraco.Web.Routing
if (contentService == null) throw new ArgumentNullException(nameof(contentService));
if (logger == null) throw new ArgumentNullException(nameof(logger));
if (publishedUrlProvider == null) throw new ArgumentNullException(nameof(publishedUrlProvider));
if (uriUtility == null) throw new ArgumentNullException(nameof(uriUtility));
if (variationContextAccessor == null) throw new ArgumentNullException(nameof(variationContextAccessor));
if (content.Published == false)
@@ -61,7 +63,7 @@ namespace Umbraco.Web.Routing
//get all URLs for all cultures
//in a HashSet, so de-duplicates too
foreach (var cultureUrl in GetContentUrlsByCulture(content, cultures, publishedRouter, umbracoContext, contentService, textService, variationContextAccessor, logger, publishedUrlProvider))
foreach (var cultureUrl in GetContentUrlsByCulture(content, cultures, publishedRouter, umbracoContext, contentService, textService, variationContextAccessor, logger, uriUtility, publishedUrlProvider))
{
urls.Add(cultureUrl);
}
@@ -103,6 +105,7 @@ namespace Umbraco.Web.Routing
ILocalizedTextService textService,
IVariationContextAccessor variationContextAccessor,
ILogger logger,
UriUtility uriUtility,
IPublishedUrlProvider publishedUrlProvider)
{
foreach (var culture in cultures)
@@ -138,7 +141,7 @@ namespace Umbraco.Web.Routing
// got a url, deal with collisions, add url
default:
if (DetectCollision(content, url, culture, umbracoContext, publishedRouter, textService, variationContextAccessor, out var urlInfo)) // detect collisions, etc
if (DetectCollision(content, url, culture, umbracoContext, publishedRouter, textService, variationContextAccessor, uriUtility, out var urlInfo)) // detect collisions, etc
yield return urlInfo;
else
yield return UrlInfo.Url(url, culture);
@@ -168,12 +171,12 @@ namespace Umbraco.Web.Routing
return UrlInfo.Message(textService.Localize("content/parentCultureNotPublished", new[] {parent.Name}), culture);
}
private static bool DetectCollision(IContent content, string url, string culture, IUmbracoContext umbracoContext, IPublishedRouter publishedRouter, ILocalizedTextService textService, IVariationContextAccessor variationContextAccessor, out UrlInfo urlInfo)
private static bool DetectCollision(IContent content, string url, string culture, IUmbracoContext umbracoContext, IPublishedRouter publishedRouter, ILocalizedTextService textService, IVariationContextAccessor variationContextAccessor, UriUtility uriUtility, out UrlInfo urlInfo)
{
// test for collisions on the 'main' url
var uri = new Uri(url.TrimEnd('/'), UriKind.RelativeOrAbsolute);
if (uri.IsAbsoluteUri == false) uri = uri.MakeAbsolute(umbracoContext.CleanedUmbracoUrl);
uri = UriUtility.UriToUmbraco(uri);
uri = uriUtility.UriToUmbraco(uri);
var pcr = publishedRouter.CreateRequest(umbracoContext, uri);
publishedRouter.TryRouteRequest(pcr);
@@ -22,6 +22,7 @@ using Umbraco.Core.Strings;
using Umbraco.Core.Sync;
using Umbraco.Web.Models.PublishedContent;
using Umbraco.Web.PublishedCache;
using Umbraco.Web;
using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator;
namespace Umbraco.Core.Runtime
@@ -139,6 +140,7 @@ namespace Umbraco.Core.Runtime
composition.SetCultureDictionaryFactory<DefaultCultureDictionaryFactory>();
composition.Register(f => f.GetInstance<ICultureDictionaryFactory>().CreateDictionary(), Lifetime.Singleton);
composition.RegisterUnique<UriUtility>();
// register the published snapshot accessor - the "current" published snapshot is in the umbraco context
composition.RegisterUnique<IPublishedSnapshotAccessor, UmbracoContextPublishedSnapshotAccessor>();
@@ -164,6 +164,7 @@ namespace Umbraco.Tests.Cache
TestObjects.GetGlobalSettings(),
Mock.Of<IUserService>(),
IOHelper,
UriUtility,
httpContextAccessor);
// just assert it does not throw
@@ -82,7 +82,8 @@ namespace Umbraco.Tests.Cache.PublishedCache
new WebSecurity(httpContextAccessor, Mock.Of<IUserService>(), globalSettings, IOHelper),
globalSettings,
new TestVariationContextAccessor(),
IOHelper);
IOHelper,
UriUtility);
_cache = _umbracoContext.Content;
}
@@ -12,6 +12,8 @@ namespace Umbraco.Tests.Misc
[TestFixture]
public class UriUtilityTests
{
public UriUtility UriUtility { get; } = TestHelper.UriUtility;
[TearDown]
public void TearDown()
{
@@ -76,7 +76,8 @@ namespace Umbraco.Tests.PublishedContent
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper),
globalSettings,
new TestVariationContextAccessor(),
IOHelper);
IOHelper,
UriUtility);
return umbracoContext;
}
@@ -48,7 +48,8 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext(urlAsString);
var publishedRouter = CreatePublishedRouter();
var frequest = publishedRouter.CreateRequest(umbracoContext);
var lookup = new ContentFinderByUrlAlias(Logger);
var lookup =
new ContentFinderByUrlAlias(Logger, Mock.Of<IPublishedValueFallback>(), VariationContextAccessor);
var result = lookup.TryFindContent(frequest);
@@ -20,10 +20,16 @@ namespace Umbraco.Tests.Routing
var properties = new[]
{
new PublishedPropertyType("umbracoUrlAlias", Constants.DataTypes.Textbox, false, ContentVariation.Nothing,
new PropertyValueConverterCollection(Enumerable.Empty<IPropertyValueConverter>()),
Mock.Of<IPublishedModelFactory>(),
Mock.Of<IPublishedContentTypeFactory>()),
new PublishedPropertyType(
propertyTypeAlias:"umbracoUrlAlias",
dataTypeId: Constants.DataTypes.Textbox,
isUserProperty:false,
variations: ContentVariation.Nothing,
propertyValueConverters:new PropertyValueConverterCollection(Enumerable.Empty<IPropertyValueConverter>()),
contentType:Mock.Of<IPublishedContentType>(),
publishedModelFactory:Mock.Of<IPublishedModelFactory>(),
factory:Mock.Of<IPublishedContentTypeFactory>()
)
};
_publishedContentType = new PublishedContentType(0, "Doc", PublishedItemType.Content, Enumerable.Empty<string>(), properties, ContentVariation.Nothing);
}
@@ -57,7 +63,7 @@ namespace Umbraco.Tests.Routing
if (expectedNode > 0)
Assert.AreEqual(expectedCulture, request.Culture.Name);
var finder = new ContentFinderByUrlAlias(Logger);
var finder = new ContentFinderByUrlAlias(Logger, Mock.Of<IPublishedValueFallback>(), VariationContextAccessor);
var result = finder.TryFindContent(request);
if (expectedNode > 0)
@@ -38,7 +38,7 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext(urlAsString, template1.Id, globalSettings:globalSettings.Object);
var publishedRouter = CreatePublishedRouter();
var frequest = publishedRouter.CreateRequest(umbracoContext);
var lookup = new ContentFinderByUrlAndTemplate(Logger, ServiceContext.FileService);
var lookup = new ContentFinderByUrlAndTemplate(Logger, ServiceContext.FileService, TestObjects.GetUmbracoSettings(), ServiceContext.ContentTypeService);
var result = lookup.TryFindContent(frequest);
@@ -60,6 +60,7 @@ namespace Umbraco.Tests.Routing
GetLangService("en-US", "fr-FR"), GetTextService(), ServiceContext.ContentService,
VariationContextAccessor,
Logger,
UriUtility,
PublishedUrlProvider).ToList();
Assert.AreEqual(1, urls.Count);
@@ -80,9 +81,10 @@ namespace Umbraco.Tests.Routing
var umbContext = GetUmbracoContext("http://localhost:8000");
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbContext);
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(), umbracoContextAccessor);
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(),
umbracoContextAccessor, UriUtility);
var publishedUrlProvider = new UrlProvider(
new Lazy<IUmbracoContextAccessor>(() => umbracoContextAccessor),
umbracoContextAccessor,
TestHelper.WebRoutingSection,
new UrlProviderCollection(new []{urlProvider}),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
@@ -96,6 +98,7 @@ namespace Umbraco.Tests.Routing
GetLangService("en-US", "fr-FR"), GetTextService(), ServiceContext.ContentService,
VariationContextAccessor,
Logger,
UriUtility,
publishedUrlProvider).ToList();
Assert.AreEqual(1, urls.Count);
@@ -124,14 +127,14 @@ namespace Umbraco.Tests.Routing
var umbContext = GetUmbracoContext("http://localhost:8000");
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbContext);
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(), umbracoContextAccessor);
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = new UrlProvider(
new Lazy<IUmbracoContextAccessor>(() => umbracoContextAccessor),
umbracoContextAccessor,
TestHelper.WebRoutingSection,
new UrlProviderCollection(new []{urlProvider}),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
Mock.Of<IVariationContextAccessor>()
);
);
var publishedRouter = CreatePublishedRouter(Factory,
contentFinders: new ContentFinderCollection(new[] { new ContentFinderByUrl(Logger) }));
@@ -140,7 +143,9 @@ namespace Umbraco.Tests.Routing
GetLangService("en-US", "fr-FR"), GetTextService(), ServiceContext.ContentService,
VariationContextAccessor,
Logger,
publishedUrlProvider).ToList();
UriUtility,
publishedUrlProvider
).ToList();
Assert.AreEqual(1, urls.Count);
Assert.AreEqual("/home/sub1/", urls[0].Text);
@@ -43,7 +43,7 @@ namespace Umbraco.Tests.Routing
new FileUploadPropertyEditor(logger, mediaFileSystemMock, contentSection, dataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper, umbracoSettingsSection),
new ImageCropperPropertyEditor(logger, mediaFileSystemMock, contentSection, dataTypeService, LocalizationService, IOHelper, ShortStringHelper, LocalizedTextService, umbracoSettingsSection),
}));
_mediaUrlProvider = new DefaultMediaUrlProvider(new Lazy<PropertyEditorCollection>(() => propertyEditors));
_mediaUrlProvider = new DefaultMediaUrlProvider(new Lazy<PropertyEditorCollection>(() => propertyEditors), UriUtility);
}
public override void TearDown()
@@ -152,7 +152,7 @@ namespace Umbraco.Tests.Routing
private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext)
{
return new UrlProvider(
new Lazy<IUmbracoContextAccessor>(() => new TestUmbracoContextAccessor(umbracoContext)),
new TestUmbracoContextAccessor(umbracoContext),
TestHelper.WebRoutingSection,
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
new MediaUrlProviderCollection(new []{_mediaUrlProvider}),
@@ -43,6 +43,7 @@ namespace Umbraco.Tests.Routing
null, // FIXME: PublishedRouter complexities...
Mock.Of<IUmbracoContextFactory>(),
new RoutableDocumentFilter(globalSettings, IOHelper),
UriUtility,
AppCaches.RequestCache
);
+9 -10
View File
@@ -50,11 +50,10 @@ namespace Umbraco.Tests.Routing
var umbracoSettings = Current.Configs.Settings();
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
var requestHandlerMock = Mock.Get(umbracoSettings.RequestHandler);
@@ -102,7 +101,7 @@ namespace Umbraco.Tests.Routing
private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider)
{
return new UrlProvider(
new Lazy<IUmbracoContextAccessor>(() => new TestUmbracoContextAccessor(umbracoContext)),
new TestUmbracoContextAccessor(umbracoContext),
TestHelper.WebRoutingSection,
new UrlProviderCollection(new []{urlProvider}),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
@@ -130,7 +129,7 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
var result = publishedUrlProvider.GetUrl(nodeId);
@@ -159,7 +158,7 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
var result = publishedUrlProvider.GetUrl(nodeId);
@@ -202,7 +201,7 @@ namespace Umbraco.Tests.Routing
snapshotService: snapshotService.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
//even though we are asking for a specific culture URL, there are no domains assigned so all that can be returned is a normal relative url.
@@ -258,7 +257,7 @@ namespace Umbraco.Tests.Routing
snapshotService: snapshotService.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
@@ -313,7 +312,7 @@ namespace Umbraco.Tests.Routing
snapshotService: snapshotService.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
@@ -335,7 +334,7 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: globalSettings.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
Assert.AreEqual("/home/sub1/custom-sub-1/", publishedUrlProvider.GetUrl(1177));
@@ -353,7 +352,7 @@ namespace Umbraco.Tests.Routing
var umbracoSettings = Current.Configs.Settings();
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), UmbracoContextAccessor);
new SiteDomainHelper(), UmbracoContextAccessor, UriUtility);
var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: globalSettings.Object);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
@@ -186,7 +186,7 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
SetDomains1();
@@ -220,7 +220,7 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
SetDomains2();
@@ -246,7 +246,7 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
SetDomains3();
@@ -278,7 +278,7 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
SetDomains4();
@@ -300,7 +300,7 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
SetDomains4();
@@ -364,7 +364,7 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext("http://domain1.com/test", 1111, globalSettings:globalSettings.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
SetDomains4();
@@ -389,7 +389,7 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext("http://domain1.com/en/test", 1111, globalSettings:globalSettings.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
SetDomains5();
@@ -409,7 +409,7 @@ namespace Umbraco.Tests.Routing
private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider)
{
return new UrlProvider(
new Lazy<IUmbracoContextAccessor>(() => new TestUmbracoContextAccessor(umbracoContext)),
new TestUmbracoContextAccessor(umbracoContext),
TestHelper.WebRoutingSection,
new UrlProviderCollection(new []{urlProvider}),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
@@ -46,7 +46,7 @@ namespace Umbraco.Tests.Routing
var umbracoContext = GetUmbracoContext(url, 9999, globalSettings:globalSettings.Object);
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
new SiteDomainHelper(), umbracoContextAccessor);
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
Assert.AreEqual("http://domain2.com/1001-1-1/", publishedUrlProvider.GetUrl(100111, UrlMode.Absolute));
@@ -98,7 +98,7 @@ namespace Umbraco.Tests.Routing
private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider)
{
return new UrlProvider(
new Lazy<IUmbracoContextAccessor>(() => new TestUmbracoContextAccessor(umbracoContext)),
new TestUmbracoContextAccessor(umbracoContext),
TestHelper.WebRoutingSection,
new UrlProviderCollection(new []{urlProvider}),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
@@ -125,7 +125,8 @@ namespace Umbraco.Tests.Scoping
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper),
globalSettings,
new TestVariationContextAccessor(),
IOHelper);
IOHelper,
UriUtility);
if (setSingleton)
Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext;
@@ -36,7 +36,8 @@ namespace Umbraco.Tests.Security
Mock.Of<IPublishedSnapshotService>(),
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper), globalSettings,
new TestVariationContextAccessor(),
IOHelper);
IOHelper,
UriUtility);
var runtime = Mock.Of<IRuntimeState>(x => x.Level == RuntimeLevel.Install);
var mgr = new BackOfficeCookieManager(
@@ -58,7 +59,8 @@ namespace Umbraco.Tests.Security
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper),
globalSettings,
new TestVariationContextAccessor(),
IOHelper);
IOHelper,
UriUtility);
var runtime = Mock.Of<IRuntimeState>(x => x.Level == RuntimeLevel.Run);
var mgr = new BackOfficeCookieManager(Mock.Of<IUmbracoContextAccessor>(accessor => accessor.UmbracoContext == umbCtx), runtime, TestObjects.GetGlobalSettings(), IOHelper, AppCaches.RequestCache);
@@ -77,7 +77,7 @@ namespace Umbraco.Tests.Templates
umbracoContextAccessor: umbracoContextAccessor);
var publishedUrlProvider = new UrlProvider(new Lazy<IUmbracoContextAccessor>(() => umbracoContextAccessor),
var publishedUrlProvider = new UrlProvider(umbracoContextAccessor,
TestHelper.WebRoutingSection,
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
new MediaUrlProviderCollection(new []{mediaUrlProvider.Object}),
@@ -72,7 +72,7 @@ namespace Umbraco.Tests.Templates
var umbracoContextFactory = TestUmbracoContextFactory.Create(
umbracoContextAccessor: umbracoContextAccessor);
var publishedUrlProvider = new UrlProvider(new Lazy<IUmbracoContextAccessor>(() => umbracoContextAccessor),
var publishedUrlProvider = new UrlProvider(umbracoContextAccessor,
TestHelper.WebRoutingSection,
new UrlProviderCollection(new []{contentUrlProvider.Object}),
new MediaUrlProviderCollection(new []{mediaUrlProvider.Object}),
@@ -143,7 +143,8 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
webSecurity.Object,
globalSettings,
new TestVariationContextAccessor(),
TestHelper.IOHelper);
TestHelper.IOHelper,
TestHelper.UriUtility);
//replace it
umbracoContextAccessor.UmbracoContext = umbCtx;
@@ -102,6 +102,8 @@ namespace Umbraco.Tests.TestHelpers
public static IIOHelper IOHelper { get; } = new IOHelper(GetHostingEnvironment());
public static IMainDom MainDom { get; } = new MainDom(Mock.Of<ILogger>(), GetHostingEnvironment(), new MainDomSemaphoreLock(Mock.Of<ILogger>(), GetHostingEnvironment()));
public static UriUtility UriUtility { get; } = new UriUtility(GetHostingEnvironment());
public static IWebRoutingSection WebRoutingSection => SettingsForTests.GetDefaultUmbracoSettings().WebRouting;
/// <summary>
@@ -133,6 +133,7 @@ namespace Umbraco.Tests.TestHelpers
globalSettings,
Mock.Of<IUserService>(),
TestHelper.IOHelper,
TestHelper.UriUtility,
httpContextAccessor);
return umbracoContextFactory.EnsureUmbracoContext().UmbracoContext;
@@ -381,7 +381,8 @@ namespace Umbraco.Tests.TestHelpers
Factory.GetInstance<IGlobalSettings>(), IOHelper),
globalSettings ?? Factory.GetInstance<IGlobalSettings>(),
new TestVariationContextAccessor(),
IOHelper);
IOHelper,
UriUtility);
if (setSingleton)
Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext;
@@ -44,6 +44,7 @@ namespace Umbraco.Tests.Testing.Objects
globalSettings,
Mock.Of<IUserService>(),
TestHelper.IOHelper,
TestHelper.UriUtility,
httpContextAccessor);
return umbracoContextFactory;
@@ -86,7 +86,7 @@ namespace Umbraco.Tests.Testing.TestingTests
var urlProvider = urlProviderMock.Object;
var theUrlProvider = new UrlProvider(
new Lazy<IUmbracoContextAccessor>(() => new TestUmbracoContextAccessor(umbracoContext)),
new TestUmbracoContextAccessor(umbracoContext),
TestHelper.WebRoutingSection,
new UrlProviderCollection(new [] { urlProvider }),
new MediaUrlProviderCollection( Enumerable.Empty<IMediaUrlProvider>())
+8 -8
View File
@@ -115,6 +115,7 @@ namespace Umbraco.Tests.Testing
protected IJsonSerializer JsonNetSerializer { get; } = new JsonNetSerializer();
protected IIOHelper IOHelper { get; private set; }
protected UriUtility UriUtility => new UriUtility(HostingEnvironment);
protected IPublishedUrlProvider PublishedUrlProvider => Factory.GetInstance<IPublishedUrlProvider>();
protected IDataTypeService DataTypeService => Factory.GetInstance<IDataTypeService>();
protected IPasswordHasher PasswordHasher => Factory.GetInstance<IPasswordHasher>();
@@ -130,7 +131,7 @@ namespace Umbraco.Tests.Testing
protected virtual IProfilingLogger ProfilingLogger => Factory.GetInstance<IProfilingLogger>();
protected IHostingEnvironment HostingEnvironment => Factory.GetInstance<IHostingEnvironment>();
protected IHostingEnvironment HostingEnvironment { get; } = new AspNetHostingEnvironment(SettingsForTests.GetDefaultHostingSettings());
protected IIpResolver IpResolver => Factory.GetInstance<IIpResolver>();
protected IBackOfficeInfo BackOfficeInfo => Factory.GetInstance<IBackOfficeInfo>();
protected AppCaches AppCaches => Factory.GetInstance<AppCaches>();
@@ -163,20 +164,18 @@ namespace Umbraco.Tests.Testing
var proflogger = new ProfilingLogger(logger, profiler);
IOHelper = TestHelper.IOHelper;
TypeFinder = new TypeFinder(logger);
var appCaches = GetAppCaches();
var globalSettings = SettingsForTests.GetDefaultGlobalSettings();
var hostingSettings = SettingsForTests.GetDefaultHostingSettings();
var settings = SettingsForTests.GetDefaultUmbracoSettings();
IHostingEnvironment hostingEnvironment = new AspNetHostingEnvironment(hostingSettings);
IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, IOHelper, settings, logger);
IIpResolver ipResolver = new AspNetIpResolver();
UmbracoVersion = new UmbracoVersion(globalSettings);
LocalizedTextService = new LocalizedTextService(new Dictionary<CultureInfo, Lazy<XDocument>>(), logger);
var typeLoader = GetTypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, hostingEnvironment, proflogger, Options.TypeLoader);
var typeLoader = GetTypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, HostingEnvironment, proflogger, Options.TypeLoader);
var register = TestHelper.GetRegister();
@@ -187,6 +186,7 @@ namespace Umbraco.Tests.Testing
Composition.RegisterUnique(IOHelper);
Composition.RegisterUnique(UriUtility);
Composition.RegisterUnique(UmbracoVersion);
Composition.RegisterUnique(TypeFinder);
Composition.RegisterUnique(LocalizedTextService);
@@ -195,7 +195,7 @@ namespace Umbraco.Tests.Testing
Composition.RegisterUnique(profiler);
Composition.RegisterUnique<IProfilingLogger>(proflogger);
Composition.RegisterUnique(appCaches);
Composition.RegisterUnique(hostingEnvironment);
Composition.RegisterUnique(HostingEnvironment);
Composition.RegisterUnique(backOfficeInfo);
Composition.RegisterUnique(ipResolver);
Composition.RegisterUnique<IPasswordHasher, AspNetPasswordHasher>();
@@ -302,7 +302,7 @@ namespace Umbraco.Tests.Testing
Composition.RegisterUnique<IPublishedValueFallback, NoopPublishedValueFallback>();
Composition.RegisterUnique<IPublishedUrlProvider>(factory =>
new UrlProvider(
new Lazy<IUmbracoContextAccessor>(() => factory.GetInstance<IUmbracoContextAccessor>()),
factory.GetInstance<IUmbracoContextAccessor>(),
TestObjects.GetUmbracoSettings().WebRouting,
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
@@ -522,7 +522,7 @@ namespace Umbraco.Tests.Testing
Current.Reset(); // disposes the factory
// reset all other static things that should not be static ;(
UriUtility.ResetAppDomainAppVirtualPath();
UriUtility.ResetAppDomainAppVirtualPath(HostingEnvironment);
SettingsForTests.Reset(); // FIXME: should it be optional?
// clear static events
@@ -73,6 +73,7 @@ namespace Umbraco.Tests.Web.Mvc
globalSettings,
Mock.Of<IUserService>(),
TestHelper.IOHelper,
TestHelper.UriUtility,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
@@ -103,6 +104,7 @@ namespace Umbraco.Tests.Web.Mvc
globalSettings,
Mock.Of<IUserService>(),
TestHelper.IOHelper,
TestHelper.UriUtility,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
@@ -133,6 +135,7 @@ namespace Umbraco.Tests.Web.Mvc
globalSettings,
Mock.Of<IUserService>(),
TestHelper.IOHelper,
TestHelper.UriUtility,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
@@ -163,6 +166,7 @@ namespace Umbraco.Tests.Web.Mvc
globalSettings,
Mock.Of<IUserService>(),
TestHelper.IOHelper,
TestHelper.UriUtility,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
@@ -46,6 +46,7 @@ namespace Umbraco.Tests.Web.Mvc
globalSettings,
Mock.Of<IUserService>(),
IOHelper,
UriUtility,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
@@ -74,6 +75,7 @@ namespace Umbraco.Tests.Web.Mvc
globalSettings,
Mock.Of<IUserService>(),
IOHelper,
UriUtility,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
@@ -105,6 +107,7 @@ namespace Umbraco.Tests.Web.Mvc
globalSettings,
Mock.Of<IUserService>(),
IOHelper,
UriUtility,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
@@ -142,6 +145,7 @@ namespace Umbraco.Tests.Web.Mvc
globalSettings,
Mock.Of<IUserService>(),
IOHelper,
UriUtility,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
@@ -444,7 +444,8 @@ namespace Umbraco.Tests.Web.Mvc
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper),
globalSettings,
new TestVariationContextAccessor(),
IOHelper);
IOHelper,
UriUtility);
//if (setSingleton)
//{
@@ -35,7 +35,8 @@ namespace Umbraco.Tests.Web
new WebSecurity(httpContextAccessor, Current.Services.UserService, TestObjects.GetGlobalSettings(), IOHelper),
TestObjects.GetGlobalSettings(),
new TestVariationContextAccessor(),
IOHelper);
IOHelper,
UriUtility);
var r1 = new RouteData();
r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx);
@@ -54,7 +55,8 @@ namespace Umbraco.Tests.Web
new WebSecurity(httpContextAccessor, Current.Services.UserService, TestObjects.GetGlobalSettings(), IOHelper),
TestObjects.GetGlobalSettings(),
new TestVariationContextAccessor(),
IOHelper);
IOHelper,
UriUtility);
var r1 = new RouteData();
r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx);
@@ -83,7 +85,8 @@ namespace Umbraco.Tests.Web
new WebSecurity(httpContextAccessor, Current.Services.UserService, TestObjects.GetGlobalSettings(), IOHelper),
TestObjects.GetGlobalSettings(),
new TestVariationContextAccessor(),
IOHelper);
IOHelper,
UriUtility);
var httpContext = Mock.Of<HttpContextBase>();
@@ -8,7 +8,6 @@ using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Core.Strings;
using Umbraco.Web.Composing;
using Umbraco.Web.Editors;
using Umbraco.Web.Routing;
@@ -17,7 +16,7 @@ namespace Umbraco.Web.Macros
/// <summary>
/// Legacy class used by macros which converts a published content item into a hashset of values
/// </summary>
public class PublishedContentHashtableConverter
internal class PublishedContentHashtableConverter
{
#region Constructors
@@ -32,6 +32,7 @@ namespace Umbraco.Web.Models.Mapping
private readonly IUserService _userService;
private readonly IVariationContextAccessor _variationContextAccessor;
private readonly IPublishedUrlProvider _publishedUrlProvider;
private readonly UriUtility _uriUtility;
private readonly TabsAndPropertiesMapper<IContent> _tabsAndPropertiesMapper;
private readonly ContentSavedStateMapper<ContentPropertyDisplay> _stateMapper;
private readonly ContentBasicSavedStateMapper<ContentPropertyBasic> _basicStateMapper;
@@ -39,7 +40,7 @@ namespace Umbraco.Web.Models.Mapping
public ContentMapDefinition(CommonMapper commonMapper, ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService, IContentService contentService, IContentTypeService contentTypeService,
IFileService fileService, IUmbracoContextAccessor umbracoContextAccessor, IPublishedRouter publishedRouter, ILocalizationService localizationService, ILogger logger,
IUserService userService, IVariationContextAccessor variationContextAccessor, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IPublishedUrlProvider publishedUrlProvider)
IUserService userService, IVariationContextAccessor variationContextAccessor, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, UriUtility uriUtility, IPublishedUrlProvider publishedUrlProvider)
{
_commonMapper = commonMapper;
_cultureDictionary = cultureDictionary;
@@ -53,6 +54,7 @@ namespace Umbraco.Web.Models.Mapping
_logger = logger;
_userService = userService;
_variationContextAccessor = variationContextAccessor;
_uriUtility = uriUtility;
_publishedUrlProvider = publishedUrlProvider;
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IContent>(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider);
@@ -179,7 +181,7 @@ namespace Umbraco.Web.Models.Mapping
var urls = umbracoContext == null
? new[] { UrlInfo.Message("Cannot generate urls without a current Umbraco Context") }
: source.GetContentUrls(_publishedRouter, umbracoContext, _localizationService, _localizedTextService, _contentService, _variationContextAccessor, _logger, _publishedUrlProvider).ToArray();
: source.GetContentUrls(_publishedRouter, umbracoContext, _localizationService, _localizedTextService, _contentService, _variationContextAccessor, _logger, _uriUtility, _publishedUrlProvider).ToArray();
return urls;
}
+1 -1
View File
@@ -8,7 +8,7 @@ namespace Umbraco.Web
{
public string GetCurrentRequestIpAddress()
{
var httpContext = HttpContext.Current == null ? (HttpContextBase) null : new HttpContextWrapper(HttpContext.Current);
var httpContext = HttpContext.Current is null ? null : new HttpContextWrapper(HttpContext.Current);
var ip = httpContext.GetCurrentRequestIpAddress();
if (ip.ToLowerInvariant().StartsWith("unknown")) ip = "";
return ip;
@@ -31,9 +31,6 @@ namespace Umbraco.Web.PropertyEditors
{
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IIOHelper _ioHelper;
private readonly ILogger _logger;
private readonly IMediaService _mediaService;
private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider;
private readonly HtmlImageSourceParser _imageSourceParser;
private readonly RichTextEditorPastedImages _pastedImages;
private readonly HtmlLocalLinkParser _localLinkParser;
@@ -41,8 +38,6 @@ namespace Umbraco.Web.PropertyEditors
public GridPropertyEditor(
ILogger logger,
IMediaService mediaService,
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
IUmbracoContextAccessor umbracoContextAccessor,
IDataTypeService dataTypeService,
ILocalizationService localizationService,
@@ -57,9 +52,6 @@ namespace Umbraco.Web.PropertyEditors
{
_umbracoContextAccessor = umbracoContextAccessor;
_ioHelper = ioHelper;
_logger = logger;
_mediaService = mediaService;
_contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
_imageSourceParser = imageSourceParser;
_pastedImages = pastedImages;
_localLinkParser = localLinkParser;
@@ -72,7 +64,7 @@ namespace Umbraco.Web.PropertyEditors
/// Overridden to ensure that the value is validated
/// </summary>
/// <returns></returns>
protected override IDataValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor, _logger, DataTypeService, LocalizationService, LocalizedTextService, _imageSourceParser, _pastedImages, _localLinkParser, ShortStringHelper, _imageUrlGenerator);
protected override IDataValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute,_umbracoContextAccessor, DataTypeService, LocalizationService, LocalizedTextService, _imageSourceParser, _pastedImages, _localLinkParser, ShortStringHelper, _imageUrlGenerator);
protected override IConfigurationEditor CreateConfigurationEditor() => new GridConfigurationEditor(_ioHelper);
@@ -87,10 +79,7 @@ namespace Umbraco.Web.PropertyEditors
public GridPropertyValueEditor(
DataEditorAttribute attribute,
IMediaService mediaService,
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
IUmbracoContextAccessor umbracoContextAccessor,
ILogger logger,
IDataTypeService dataTypeService,
ILocalizationService localizationService,
ILocalizedTextService localizedTextService,
@@ -73,7 +73,7 @@ namespace Umbraco.Web.PropertyEditors
/// <summary>
/// A custom value editor to ensure that macro syntax is parsed when being persisted and formatted correctly for display in the editor
/// </summary>
public class RichTextPropertyValueEditor : DataValueEditor, IDataValueReference
internal class RichTextPropertyValueEditor : DataValueEditor, IDataValueReference
{
private IUmbracoContextAccessor _umbracoContextAccessor;
private readonly HtmlImageSourceParser _imageSourceParser;
+21 -19
View File
@@ -5,6 +5,7 @@ using System.Linq;
using System.Web;
using Examine;
using Umbraco.Core;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
@@ -50,8 +51,8 @@ namespace Umbraco.Web
Current.Configs.Settings().WebRouting.DisableAlternativeTemplates,
Current.Configs.Settings().WebRouting.ValidateAlternativeTemplates,
templateId);
}
public static bool IsAllowedTemplate(this IPublishedContent content, string templateAlias)
{
return content.IsAllowedTemplate(
@@ -700,26 +701,27 @@ namespace Umbraco.Web
#region Url
/// <summary>
/// Gets the url of the content item.
/// </summary>
/// <remarks>
/// <para>If the content item is a document, then this method returns the url of the
/// document. If it is a media, then this methods return the media url for the
/// 'umbracoFile' property. Use the MediaUrl() method to get the media url for other
/// properties.</para>
/// <para>The value of this property is contextual. It depends on the 'current' request uri,
/// if any. In addition, when the content type is multi-lingual, this is the url for the
/// specified culture. Otherwise, it is the invariant url.</para>
/// </remarks>
public static string Url(this IPublishedContent content, string culture = null, UrlMode mode = UrlMode.Default)
{
var umbracoContext = Current.UmbracoContext;
/// Gets the url of the content item.
/// </summary>
/// <remarks>
/// <para>If the content item is a document, then this method returns the url of the
/// document. If it is a media, then this methods return the media url for the
/// 'umbracoFile' property. Use the MediaUrl() method to get the media url for other
/// properties.</para>
/// <para>The value of this property is contextual. It depends on the 'current' request uri,
/// if any. In addition, when the content type is multi-lingual, this is the url for the
/// specified culture. Otherwise, it is the invariant url.</para>
/// </remarks>
public static string Url(this IPublishedContent content, string culture = null, UrlMode mode = UrlMode.Default)
{
var umbracoContext = Current.UmbracoContext;
if (umbracoContext == null)
throw new InvalidOperationException("Cannot resolve a Url when Current.UmbracoContext is null.");
if (umbracoContext == null)
throw new InvalidOperationException("Cannot resolve a Url when Current.UmbracoContext is null.");
return content.Url(Current.PublishedUrlProvider, culture, mode);
}
return content.Url(Current.PublishedUrlProvider, culture, mode);
}
#endregion
}
-26
View File
@@ -200,11 +200,6 @@
<Compile Include="PropertyEditors\RichTextPropertyEditor.cs" />
<Compile Include="PropertyEditors\ValueConverters\RteMacroRenderingValueConverter.cs" />
<Compile Include="RoutableDocumentFilter.cs" />
<Compile Include="Routing\DefaultMediaUrlProvider.cs" />
<Compile Include="Routing\IMediaUrlProvider.cs" />
<Compile Include="Routing\IPublishedRouter.cs" />
<Compile Include="Routing\MediaUrlProviderCollection.cs" />
<Compile Include="Routing\MediaUrlProviderCollectionBuilder.cs" />
<Compile Include="Runtime\AspNetUmbracoBootPermissionChecker.cs" />
<Compile Include="Search\BackgroundIndexRebuilder.cs" />
<Compile Include="Search\ExamineFinalComponent.cs" />
@@ -324,13 +319,6 @@
<Compile Include="PropertyEditors\NestedContentController.cs" />
<Compile Include="PublishedElementExtensions.cs" />
<Compile Include="PublishedModels\DummyClassSoThatPublishedModelsNamespaceExists.cs" />
<Compile Include="Routing\ContentFinderByUrl.cs" />
<Compile Include="Routing\ContentFinderByUrlAndTemplate.cs" />
<Compile Include="Routing\ContentFinderCollection.cs" />
<Compile Include="Routing\ContentFinderCollectionBuilder.cs" />
<Compile Include="Routing\IContentLastChanceFinder.cs" />
<Compile Include="Routing\UrlProviderCollection.cs" />
<Compile Include="Routing\UrlProviderCollectionBuilder.cs" />
<Compile Include="Search\UmbracoTreeSearcher.cs" />
<Compile Include="Security\AuthenticationExtensions.cs" />
<Compile Include="Security\UmbracoSecureDataFormat.cs" />
@@ -377,7 +365,6 @@
<Compile Include="Routing\RedirectTrackingComponent.cs" />
<Compile Include="Editors\RedirectUrlManagementController.cs" />
<Compile Include="DefaultEventMessagesFactory.cs" />
<Compile Include="Routing\ContentFinderByRedirectUrl.cs" />
<Compile Include="Security\ExternalSignInAutoLinkOptions.cs" />
<Compile Include="Security\FixWindowsAuthMiddlware.cs" />
<Compile Include="Security\ForceRenewalCookieAuthenticationHandler.cs" />
@@ -465,7 +452,6 @@
<Compile Include="PublishedContentQuery.cs" />
<Compile Include="ImageCropperTemplateExtensions.cs" />
<Compile Include="Mvc\UmbracoVirtualNodeRouteHandler.cs" />
<Compile Include="Routing\UrlProviderExtensions.cs" />
<Compile Include="Security\AppBuilderExtensions.cs" />
<Compile Include="Security\AuthenticationOptionsExtensions.cs" />
<Compile Include="Security\AuthenticationManagerExtensions.cs" />
@@ -611,16 +597,9 @@
<Compile Include="Mvc\PluginControllerMetadata.cs" />
<Compile Include="Mvc\UmbracoPageResult.cs" />
<Compile Include="RouteCollectionExtensions.cs" />
<Compile Include="Routing\AliasUrlProvider.cs" />
<Compile Include="Routing\ContentFinderByConfigured404.cs" />
<Compile Include="Routing\ContentFinderByPageIdQuery.cs" />
<Compile Include="Routing\RoutableAttemptEventArgs.cs" />
<Compile Include="Routing\DefaultUrlProvider.cs" />
<Compile Include="Routing\IUrlProvider.cs" />
<Compile Include="Routing\SiteDomainHelper.cs" />
<Compile Include="Routing\EnsureRoutableOutcome.cs" />
<Compile Include="Routing\PublishedRouter.cs" />
<Compile Include="Routing\UrlProvider.cs" />
<Compile Include="Search\ExamineSearcherModel.cs" />
<Compile Include="Search\ExamineComponent.cs" />
<Compile Include="Compose\DatabaseServerRegistrarAndMessengerComponent.cs" />
@@ -642,24 +621,19 @@
<Compile Include="Mvc\RenderViewEngine.cs" />
<Compile Include="Mvc\RouteDefinition.cs" />
<Compile Include="Mvc\RouteValueDictionaryExtensions.cs" />
<Compile Include="Routing\UmbracoRequestEventArgs.cs" />
<Compile Include="WebApi\UmbracoAuthorizeAttribute.cs" />
<Compile Include="WebApi\UmbracoAuthorizedApiController.cs" />
<Compile Include="WebApi\Filters\ValidationFilterAttribute.cs" />
<Compile Include="WebApi\Filters\UmbracoUserTimeoutFilterAttribute.cs" />
<Compile Include="Runtime\WebRuntime.cs" />
<Compile Include="Mvc\ControllerExtensions.cs" />
<Compile Include="Routing\ContentFinderByUrlAlias.cs" />
<Compile Include="Routing\ContentFinderByIdPath.cs" />
<Compile Include="TypeLoaderExtensions.cs" />
<Compile Include="Routing\PublishedRequest.cs" />
<Compile Include="Routing\IContentFinder.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="UmbracoApplication.cs" />
<Compile Include="UmbracoInjectedModule.cs" />
<Compile Include="UriUtility.cs" />
<Compile Include="Web References\org.umbraco.update\Reference.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
+5 -2
View File
@@ -19,6 +19,7 @@ namespace Umbraco.Web
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IGlobalSettings _globalSettings;
private readonly IIOHelper _ioHelper;
private readonly UriUtility _uriUtility;
private readonly Lazy<IPublishedSnapshot> _publishedSnapshot;
private string _previewToken;
private bool? _previewing;
@@ -32,7 +33,8 @@ namespace Umbraco.Web
IWebSecurity webSecurity,
IGlobalSettings globalSettings,
IVariationContextAccessor variationContextAccessor,
IIOHelper ioHelper)
IIOHelper ioHelper,
UriUtility uriUtility)
{
if (httpContextAccessor == null) throw new ArgumentNullException(nameof(httpContextAccessor));
if (publishedSnapshotService == null) throw new ArgumentNullException(nameof(publishedSnapshotService));
@@ -41,6 +43,7 @@ namespace Umbraco.Web
_httpContextAccessor = httpContextAccessor;
_globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
_uriUtility = uriUtility;
// ensure that this instance is disposed when the request terminates, though we *also* ensure
// this happens in the Umbraco module since the UmbracoCOntext is added to the HttpContext items.
@@ -67,7 +70,7 @@ namespace Umbraco.Web
// see: http://issues.umbraco.org/issue/U4-1890
//
OriginalRequestUrl = GetRequestFromContext()?.Url ?? new Uri("http://localhost");
CleanedUmbracoUrl = UriUtility.UriToUmbraco(OriginalRequestUrl);
CleanedUmbracoUrl = _uriUtility.UriToUmbraco(OriginalRequestUrl);
}
/// <summary>
+13 -8
View File
@@ -1,17 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Hosting;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Web.Security;
namespace Umbraco.Web
@@ -32,11 +26,21 @@ namespace Umbraco.Web
private readonly IUserService _userService;
private readonly IIOHelper _ioHelper;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly UriUtility _uriUtility;
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoContextFactory"/> class.
/// </summary>
public UmbracoContextFactory(IUmbracoContextAccessor umbracoContextAccessor, IPublishedSnapshotService publishedSnapshotService, IVariationContextAccessor variationContextAccessor, IDefaultCultureAccessor defaultCultureAccessor, IGlobalSettings globalSettings, IUserService userService, IIOHelper ioHelper, IHttpContextAccessor httpContextAccessor)
public UmbracoContextFactory(
IUmbracoContextAccessor umbracoContextAccessor,
IPublishedSnapshotService publishedSnapshotService,
IVariationContextAccessor variationContextAccessor,
IDefaultCultureAccessor defaultCultureAccessor,
IGlobalSettings globalSettings,
IUserService userService,
IIOHelper ioHelper,
UriUtility uriUtility,
IHttpContextAccessor httpContextAccessor)
{
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
_publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService));
@@ -45,6 +49,7 @@ namespace Umbraco.Web
_globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
_ioHelper = ioHelper;
_uriUtility = uriUtility;
_httpContextAccessor = httpContextAccessor;
}
@@ -64,7 +69,7 @@ namespace Umbraco.Web
var webSecurity = new WebSecurity(_httpContextAccessor, _userService, _globalSettings, _ioHelper);
return new UmbracoContext(_httpContextAccessor, _publishedSnapshotService, webSecurity, _globalSettings, _variationContextAccessor, _ioHelper);
return new UmbracoContext(_httpContextAccessor, _publishedSnapshotService, webSecurity, _globalSettings, _variationContextAccessor, _ioHelper, _uriUtility);
}
/// <inheritdoc />
+7 -4
View File
@@ -40,6 +40,7 @@ namespace Umbraco.Web
private readonly IUmbracoContextFactory _umbracoContextFactory;
private readonly RoutableDocumentFilter _routableDocumentLookup;
private readonly IRequestCache _requestCache;
private readonly UriUtility _uriUtility;
public UmbracoInjectedModule(
IGlobalSettings globalSettings,
@@ -48,6 +49,7 @@ namespace Umbraco.Web
IPublishedRouter publishedRouter,
IUmbracoContextFactory umbracoContextFactory,
RoutableDocumentFilter routableDocumentLookup,
UriUtility uriUtility,
IRequestCache requestCache)
{
_globalSettings = globalSettings;
@@ -56,6 +58,7 @@ namespace Umbraco.Web
_publishedRouter = publishedRouter;
_umbracoContextFactory = umbracoContextFactory;
_routableDocumentLookup = routableDocumentLookup;
_uriUtility = uriUtility;
_requestCache = requestCache;
}
@@ -121,7 +124,7 @@ namespace Umbraco.Web
var isRoutableAttempt = EnsureUmbracoRoutablePage(umbracoContext, httpContext);
// raise event here
UmbracoModule.OnRouteAttempt(this, new RoutableAttemptEventArgs(isRoutableAttempt.Result, umbracoContext, httpContext));
UmbracoModule.OnRouteAttempt(this, new RoutableAttemptEventArgs(isRoutableAttempt.Result, umbracoContext));
if (isRoutableAttempt.Success == false) return;
httpContext.Trace.Write("UmbracoModule", "Umbraco request confirmed");
@@ -210,7 +213,7 @@ namespace Umbraco.Web
case RuntimeLevel.Upgrade:
// redirect to install
ReportRuntime(level, "Umbraco must install or upgrade.");
var installPath = UriUtility.ToAbsolute(Constants.SystemDirectories.Install);
var installPath = _uriUtility.ToAbsolute(Constants.SystemDirectories.Install);
var installUrl = $"{installPath}/?redir=true&url={HttpUtility.UrlEncode(uri.ToString())}";
httpContext.Response.Redirect(installUrl, true);
return false; // cannot serve content
@@ -242,7 +245,7 @@ namespace Umbraco.Web
_logger.Warn<UmbracoModule>("Umbraco has no content");
const string noContentUrl = "~/config/splashes/noNodes.aspx";
httpContext.RewritePath(UriUtility.ToAbsolute(noContentUrl));
httpContext.RewritePath(_uriUtility.ToAbsolute(noContentUrl));
return false;
}
@@ -430,7 +433,7 @@ namespace Umbraco.Web
_logger.Verbose<UmbracoModule>("End Request [{HttpRequestId}]: {RequestUrl} ({RequestDuration}ms)", httpRequestId, httpContext.Request.Url, DateTime.Now.Subtract(Current.UmbracoContext.ObjectCreated).TotalMilliseconds);
}
UmbracoModule.OnEndRequest(this, new UmbracoRequestEventArgs(Current.UmbracoContext, new HttpContextWrapper(httpContext)));
UmbracoModule.OnEndRequest(this, new UmbracoRequestEventArgs(Current.UmbracoContext));
DisposeRequestCacheItems(httpContext, _requestCache);
};