Netcore: Move files from Web/Routing to Abstractions/Routing (#7642)
* AB4951 - Move routing files to abstractions * Changed UriUtility from static to instance * Moved more files from Routing in web to Abstractions * Moved UrlProvider to Abstractions * Moved PublishedRequest to Abstractions
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
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.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
@@ -144,6 +147,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)
|
||||
@@ -1075,5 +1086,36 @@ namespace Umbraco.Core
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <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, IPublishedUrlProvider publishedUrlProvider, string culture = null, UrlMode mode = UrlMode.Default)
|
||||
{
|
||||
if (publishedUrlProvider == null)
|
||||
throw new InvalidOperationException("Cannot resolve a Url when Current.UmbracoContext.UrlProvider is null.");
|
||||
|
||||
switch (content.ContentType.ItemType)
|
||||
{
|
||||
case PublishedItemType.Content:
|
||||
return publishedUrlProvider.GetUrl(content, mode, culture);
|
||||
|
||||
case PublishedItemType.Media:
|
||||
return publishedUrlProvider.GetMediaUrl(content, mode, culture, Constants.Conventions.Media.File);
|
||||
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+10
-6
@@ -16,12 +16,16 @@ namespace Umbraco.Web.Routing
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IRequestHandlerSection _requestConfig;
|
||||
private readonly ISiteDomainHelper _siteDomainHelper;
|
||||
private readonly UriUtility _uriUtility;
|
||||
private readonly IPublishedValueFallback _publishedValueFallback;
|
||||
|
||||
public AliasUrlProvider(IGlobalSettings globalSettings, IRequestHandlerSection requestConfig, ISiteDomainHelper siteDomainHelper)
|
||||
public AliasUrlProvider(IGlobalSettings globalSettings, IRequestHandlerSection requestConfig, ISiteDomainHelper siteDomainHelper, UriUtility uriUtility, IPublishedValueFallback publishedValueFallback)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
_requestConfig = requestConfig;
|
||||
_siteDomainHelper = siteDomainHelper;
|
||||
_uriUtility = uriUtility;
|
||||
_publishedValueFallback = publishedValueFallback;
|
||||
}
|
||||
|
||||
// note - at the moment we seem to accept pretty much anything as an alias
|
||||
@@ -83,7 +87,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)
|
||||
@@ -93,7 +97,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
|
||||
@@ -108,8 +112,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);
|
||||
|
||||
@@ -120,7 +124,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -17,11 +17,13 @@ namespace Umbraco.Web.Routing
|
||||
{
|
||||
private readonly IRedirectUrlService _redirectUrlService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
|
||||
public ContentFinderByRedirectUrl(IRedirectUrlService redirectUrlService, ILogger logger)
|
||||
public ContentFinderByRedirectUrl(IRedirectUrlService redirectUrlService, ILogger logger, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
{
|
||||
_redirectUrlService = redirectUrlService;
|
||||
_logger = logger;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
}
|
||||
|
||||
/// <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(_umbracoContextAccessor.UmbracoContext.UrlProvider, redirectUrl.Culture);
|
||||
if (url.StartsWith("#"))
|
||||
{
|
||||
_logger.Debug<ContentFinderByRedirectUrl>("Route {Route} matches content {ContentId} which has no url.", route, redirectUrl.ContentId);
|
||||
+10
-6
@@ -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;
|
||||
}
|
||||
|
||||
+7
-5
@@ -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
|
||||
+4
-2
@@ -11,10 +11,12 @@ namespace Umbraco.Web.Routing
|
||||
public class DefaultMediaUrlProvider : IMediaUrlProvider
|
||||
{
|
||||
private readonly PropertyEditorCollection _propertyEditors;
|
||||
private readonly UriUtility _uriUtility;
|
||||
|
||||
public DefaultMediaUrlProvider(PropertyEditorCollection propertyEditors)
|
||||
public DefaultMediaUrlProvider(PropertyEditorCollection propertyEditors, UriUtility uriUtility)
|
||||
{
|
||||
_propertyEditors = propertyEditors ?? throw new ArgumentNullException(nameof(propertyEditors));
|
||||
_uriUtility = uriUtility;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -70,7 +72,7 @@ namespace Umbraco.Web.Routing
|
||||
throw new ArgumentOutOfRangeException(nameof(mode));
|
||||
}
|
||||
|
||||
return UriUtility.MediaUriFromUmbraco(uri);
|
||||
return _uriUtility.MediaUriFromUmbraco(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -17,13 +17,15 @@ namespace Umbraco.Web.Routing
|
||||
private readonly ILogger _logger;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly ISiteDomainHelper _siteDomainHelper;
|
||||
private readonly UriUtility _uriUtility;
|
||||
|
||||
public DefaultUrlProvider(IRequestHandlerSection requestSettings, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper)
|
||||
public DefaultUrlProvider(IRequestHandlerSection requestSettings, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, UriUtility uriUtility)
|
||||
{
|
||||
_requestSettings = requestSettings;
|
||||
_logger = logger;
|
||||
_globalSettings = globalSettings;
|
||||
_siteDomainHelper = siteDomainHelper;
|
||||
_uriUtility = uriUtility;
|
||||
}
|
||||
|
||||
#region GetUrl
|
||||
@@ -108,7 +110,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);
|
||||
}
|
||||
}
|
||||
@@ -167,7 +169,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)
|
||||
-4
@@ -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
|
||||
+2
-2
@@ -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;
|
||||
}
|
||||
+1
-3
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -4,7 +4,6 @@ using System.Linq;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Web.Composing;
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
@@ -143,7 +142,7 @@ namespace Umbraco.Web.Routing
|
||||
var provider = _urlProviders.OfType<DefaultUrlProvider>().FirstOrDefault();
|
||||
var url = provider == null
|
||||
? route // what else?
|
||||
: provider.GetUrlFromRoute(route, Current.UmbracoContext, id, _umbracoContext.CleanedUmbracoUrl, Mode, culture)?.Text;
|
||||
: provider.GetUrlFromRoute(route, _umbracoContext, id, _umbracoContext.CleanedUmbracoUrl, Mode, culture)?.Text;
|
||||
return url ?? "#";
|
||||
}
|
||||
|
||||
+9
-6
@@ -25,7 +25,8 @@ namespace Umbraco.Web.Routing
|
||||
ILocalizedTextService textService,
|
||||
IContentService contentService,
|
||||
IVariationContextAccessor variationContextAccessor,
|
||||
ILogger logger)
|
||||
ILogger logger,
|
||||
UriUtility uriUtility)
|
||||
{
|
||||
if (content == null) throw new ArgumentNullException(nameof(content));
|
||||
if (publishedRouter == null) throw new ArgumentNullException(nameof(publishedRouter));
|
||||
@@ -34,6 +35,7 @@ namespace Umbraco.Web.Routing
|
||||
if (textService == null) throw new ArgumentNullException(nameof(textService));
|
||||
if (contentService == null) throw new ArgumentNullException(nameof(contentService));
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
if (uriUtility == null) throw new ArgumentNullException(nameof(uriUtility));
|
||||
if (variationContextAccessor == null) throw new ArgumentNullException(nameof(variationContextAccessor));
|
||||
|
||||
if (content.Published == false)
|
||||
@@ -59,7 +61,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))
|
||||
foreach (var cultureUrl in GetContentUrlsByCulture(content, cultures, publishedRouter, umbracoContext, contentService, textService, variationContextAccessor, logger, uriUtility))
|
||||
{
|
||||
urls.Add(cultureUrl);
|
||||
}
|
||||
@@ -100,7 +102,8 @@ namespace Umbraco.Web.Routing
|
||||
IContentService contentService,
|
||||
ILocalizedTextService textService,
|
||||
IVariationContextAccessor variationContextAccessor,
|
||||
ILogger logger)
|
||||
ILogger logger,
|
||||
UriUtility uriUtility)
|
||||
{
|
||||
foreach (var culture in cultures)
|
||||
{
|
||||
@@ -135,7 +138,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);
|
||||
@@ -165,12 +168,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);
|
||||
|
||||
@@ -20,6 +20,7 @@ using Umbraco.Core.Serialization;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Core.Sync;
|
||||
using Umbraco.Web;
|
||||
using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator;
|
||||
|
||||
namespace Umbraco.Core.Runtime
|
||||
@@ -137,6 +138,7 @@ namespace Umbraco.Core.Runtime
|
||||
|
||||
composition.SetCultureDictionaryFactory<DefaultCultureDictionaryFactory>();
|
||||
composition.Register(f => f.GetInstance<ICultureDictionaryFactory>().CreateDictionary(), Lifetime.Singleton);
|
||||
composition.RegisterUnique<UriUtility>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,8 @@ namespace Umbraco.Tests.Cache
|
||||
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IUserService>(),
|
||||
IOHelper);
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
|
||||
// just assert it does not throw
|
||||
var refreshers = new DistributedCacheBinder(null, umbracoContextFactory, null);
|
||||
|
||||
@@ -83,7 +83,8 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -77,7 +77,8 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
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);
|
||||
|
||||
|
||||
@@ -54,7 +54,8 @@ namespace Umbraco.Tests.Routing
|
||||
umbContext,
|
||||
GetLangService("en-US", "fr-FR"), GetTextService(), ServiceContext.ContentService,
|
||||
VariationContextAccessor,
|
||||
Logger).ToList();
|
||||
Logger,
|
||||
UriUtility).ToList();
|
||||
|
||||
Assert.AreEqual(1, urls.Count);
|
||||
Assert.AreEqual("content/itemNotPublished", urls[0].Text);
|
||||
@@ -73,13 +74,15 @@ namespace Umbraco.Tests.Routing
|
||||
var umbracoSettings = Current.Configs.Settings();
|
||||
|
||||
var umbContext = GetUmbracoContext("http://localhost:8000",
|
||||
urlProviders: new []{ new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper()) });
|
||||
urlProviders: new []{ new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(), UriUtility) });
|
||||
var publishedRouter = CreatePublishedRouter(Factory,
|
||||
contentFinders:new ContentFinderCollection(new[]{new ContentFinderByUrl(Logger) }));
|
||||
var urls = content.GetContentUrls(publishedRouter,
|
||||
umbContext,
|
||||
GetLangService("en-US", "fr-FR"), GetTextService(), ServiceContext.ContentService,
|
||||
VariationContextAccessor, Logger).ToList();
|
||||
VariationContextAccessor,
|
||||
Logger,
|
||||
UriUtility).ToList();
|
||||
|
||||
Assert.AreEqual(1, urls.Count);
|
||||
Assert.AreEqual("/home/", urls[0].Text);
|
||||
@@ -105,13 +108,15 @@ namespace Umbraco.Tests.Routing
|
||||
var umbracoSettings = Current.Configs.Settings();
|
||||
|
||||
var umbContext = GetUmbracoContext("http://localhost:8000",
|
||||
urlProviders: new[] { new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper()) });
|
||||
urlProviders: new[] { new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(), UriUtility) });
|
||||
var publishedRouter = CreatePublishedRouter(Factory,
|
||||
contentFinders: new ContentFinderCollection(new[] { new ContentFinderByUrl(Logger) }));
|
||||
var urls = child.GetContentUrls(publishedRouter,
|
||||
umbContext,
|
||||
GetLangService("en-US", "fr-FR"), GetTextService(), ServiceContext.ContentService,
|
||||
VariationContextAccessor, Logger).ToList();
|
||||
VariationContextAccessor,
|
||||
Logger,
|
||||
UriUtility).ToList();
|
||||
|
||||
Assert.AreEqual(1, urls.Count);
|
||||
Assert.AreEqual("/home/sub1/", urls[0].Text);
|
||||
|
||||
@@ -41,7 +41,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(propertyEditors);
|
||||
_mediaUrlProvider = new DefaultMediaUrlProvider(propertyEditors, UriUtility);
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
|
||||
@@ -42,7 +42,8 @@ namespace Umbraco.Tests.Routing
|
||||
logger,
|
||||
null, // FIXME: PublishedRouter complexities...
|
||||
Mock.Of<IUmbracoContextFactory>(),
|
||||
new RoutableDocumentFilter(globalSettings, IOHelper)
|
||||
new RoutableDocumentFilter(globalSettings, IOHelper),
|
||||
UriUtility
|
||||
);
|
||||
|
||||
runtime.Level = RuntimeLevel.Run;
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings: globalSettings.Object);
|
||||
|
||||
var requestHandlerMock = Mock.Get(umbracoSettings.RequestHandler);
|
||||
@@ -111,7 +111,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings: globalSettings.Object);
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings: globalSettings.Object);
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoContext = GetUmbracoContext(currentUri, umbracoSettings: umbracoSettings,
|
||||
urlProviders: new[] {
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
},
|
||||
globalSettings: globalSettings.Object,
|
||||
snapshotService: snapshotService.Object);
|
||||
@@ -233,7 +233,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoContext = GetUmbracoContext(currentUri, umbracoSettings: umbracoSettings,
|
||||
urlProviders: new[] {
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
},
|
||||
globalSettings: globalSettings.Object,
|
||||
snapshotService: snapshotService.Object);
|
||||
@@ -287,7 +287,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoContext = GetUmbracoContext(currentUri, umbracoSettings: umbracoSettings,
|
||||
urlProviders: new[] {
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
},
|
||||
globalSettings: globalSettings.Object,
|
||||
snapshotService: snapshotService.Object);
|
||||
@@ -309,7 +309,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, umbracoSettings: umbracoSettings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings: globalSettings.Object);
|
||||
|
||||
Assert.AreEqual("/home/sub1/custom-sub-1/", umbracoContext.UrlProvider.GetUrl(1177));
|
||||
@@ -328,7 +328,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings: globalSettings.Object);
|
||||
|
||||
//mock the Umbraco settings that we need
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
|
||||
SetDomains1();
|
||||
@@ -210,13 +210,13 @@ namespace Umbraco.Tests.Routing
|
||||
public void Get_Url_SimpleWithSchemeAndPath(int nodeId, string currentUrl, bool absolute, string expected)
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockUmbracoSettings();
|
||||
|
||||
|
||||
var globalSettings = Mock.Get(Factory.GetInstance<IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
|
||||
SetDomains2();
|
||||
@@ -241,7 +241,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
|
||||
SetDomains3();
|
||||
@@ -266,13 +266,13 @@ namespace Umbraco.Tests.Routing
|
||||
public void Get_Url_NestedDomains(int nodeId, string currentUrl, bool absolute, string expected)
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockUmbracoSettings();
|
||||
|
||||
|
||||
var globalSettings = Mock.Get(Factory.GetInstance<IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
|
||||
SetDomains4();
|
||||
@@ -287,13 +287,13 @@ namespace Umbraco.Tests.Routing
|
||||
public void Get_Url_DomainsAndCache()
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockUmbracoSettings();
|
||||
|
||||
|
||||
var globalSettings = Mock.Get(Factory.GetInstance<IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
|
||||
SetDomains4();
|
||||
@@ -350,13 +350,13 @@ namespace Umbraco.Tests.Routing
|
||||
public void Get_Url_Relative_Or_Absolute()
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockUmbracoSettings();
|
||||
|
||||
|
||||
var globalSettings = Mock.Get(Factory.GetInstance<IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains
|
||||
|
||||
var umbracoContext = GetUmbracoContext("http://domain1.com/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
|
||||
SetDomains4();
|
||||
@@ -380,7 +380,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoContext = GetUmbracoContext("http://domain1.com/en/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
|
||||
SetDomains5();
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Umbraco.Tests.Routing
|
||||
// get the nice url for 100111
|
||||
var umbracoContext = GetUmbracoContext(url, 9999, umbracoSettings: settings, urlProviders: new []
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
Assert.AreEqual("http://domain2.com/1001-1-1/", umbracoContext.UrlProvider.GetUrl(100111, UrlMode.Absolute));
|
||||
|
||||
|
||||
@@ -128,7 +128,8 @@ namespace Umbraco.Tests.Scoping
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper);
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
|
||||
if (setSingleton)
|
||||
Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext;
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Umbraco.Tests.Security
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, globalSettings, IOHelper),
|
||||
TestObjects.GetUmbracoSettings(), new List<IUrlProvider>(), Enumerable.Empty<IMediaUrlProvider>(), globalSettings,
|
||||
new TestVariationContextAccessor(), IOHelper);
|
||||
new TestVariationContextAccessor(), IOHelper, UriUtility);
|
||||
|
||||
var runtime = Mock.Of<IRuntimeState>(x => x.Level == RuntimeLevel.Install);
|
||||
var mgr = new BackOfficeCookieManager(
|
||||
@@ -55,7 +55,7 @@ namespace Umbraco.Tests.Security
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, globalSettings, IOHelper),
|
||||
TestObjects.GetUmbracoSettings(), new List<IUrlProvider>(), Enumerable.Empty<IMediaUrlProvider>(), globalSettings,
|
||||
new TestVariationContextAccessor(), IOHelper);
|
||||
new TestVariationContextAccessor(), 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(), TestHelper.IOHelper);
|
||||
|
||||
@@ -145,7 +145,8 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
TestHelper.IOHelper);
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.UriUtility);
|
||||
|
||||
//replace it
|
||||
umbracoContextAccessor.UmbracoContext = umbCtx;
|
||||
|
||||
@@ -100,6 +100,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());
|
||||
|
||||
/// <summary>
|
||||
/// Maps the given <paramref name="relativePath"/> making it rooted on <see cref="CurrentAssemblyDirectory"/>. <paramref name="relativePath"/> must start with <code>~/</code>
|
||||
/// </summary>
|
||||
|
||||
@@ -137,7 +137,8 @@ namespace Umbraco.Tests.TestHelpers
|
||||
urlProviders,
|
||||
mediaUrlProviders,
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper);
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.UriUtility);
|
||||
|
||||
return umbracoContextFactory.EnsureUmbracoContext(httpContext).UmbracoContext;
|
||||
}
|
||||
|
||||
@@ -391,7 +391,8 @@ namespace Umbraco.Tests.TestHelpers
|
||||
mediaUrlProviders ?? Enumerable.Empty<IMediaUrlProvider>(),
|
||||
globalSettings ?? Factory.GetInstance<IGlobalSettings>(),
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper);
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
|
||||
if (setSingleton)
|
||||
Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext;
|
||||
|
||||
@@ -43,7 +43,8 @@ namespace Umbraco.Tests.Testing.Objects
|
||||
new UrlProviderCollection(new[] { urlProvider }),
|
||||
new MediaUrlProviderCollection(new[] { mediaUrlProvider }),
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper);
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.UriUtility);
|
||||
|
||||
return umbracoContextFactory;
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ namespace Umbraco.Tests.Testing
|
||||
protected IJsonSerializer JsonNetSerializer { get; } = new JsonNetSerializer();
|
||||
|
||||
protected IIOHelper IOHelper { get; private set; }
|
||||
protected UriUtility UriUtility => new UriUtility(HostingEnvironment);
|
||||
protected IDataTypeService DataTypeService => Factory.GetInstance<IDataTypeService>();
|
||||
protected IPasswordHasher PasswordHasher => Factory.GetInstance<IPasswordHasher>();
|
||||
protected Lazy<PropertyEditorCollection> PropertyEditorCollection => new Lazy<PropertyEditorCollection>(() => Factory.GetInstance<PropertyEditorCollection>());
|
||||
@@ -127,7 +128,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>();
|
||||
@@ -160,20 +161,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();
|
||||
|
||||
@@ -184,6 +183,7 @@ namespace Umbraco.Tests.Testing
|
||||
|
||||
|
||||
Composition.RegisterUnique(IOHelper);
|
||||
Composition.RegisterUnique(UriUtility);
|
||||
Composition.RegisterUnique(UmbracoVersion);
|
||||
Composition.RegisterUnique(TypeFinder);
|
||||
Composition.RegisterUnique(LocalizedTextService);
|
||||
@@ -192,7 +192,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>();
|
||||
@@ -498,7 +498,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
|
||||
|
||||
@@ -74,7 +74,8 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper);
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.UriUtility);
|
||||
|
||||
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
|
||||
var umbCtx = umbracoContextReference.UmbracoContext;
|
||||
@@ -105,7 +106,8 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper);
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.UriUtility);
|
||||
|
||||
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
|
||||
var umbCtx = umbracoContextReference.UmbracoContext;
|
||||
@@ -136,7 +138,8 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper);
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.UriUtility);
|
||||
|
||||
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
|
||||
var umbCtx = umbracoContextReference.UmbracoContext;
|
||||
@@ -167,7 +170,8 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper);
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.UriUtility);
|
||||
|
||||
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
|
||||
var umbCtx = umbracoContextReference.UmbracoContext;
|
||||
|
||||
@@ -50,7 +50,8 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IUserService>(),
|
||||
IOHelper);
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
|
||||
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
|
||||
var umbracoContext = umbracoContextReference.UmbracoContext;
|
||||
@@ -79,7 +80,8 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IUserService>(),
|
||||
IOHelper);
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
|
||||
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
|
||||
var umbCtx = umbracoContextReference.UmbracoContext;
|
||||
@@ -111,7 +113,8 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IUserService>(),
|
||||
IOHelper);
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
|
||||
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
|
||||
var umbracoContext = umbracoContextReference.UmbracoContext;
|
||||
@@ -150,7 +153,8 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IUserService>(),
|
||||
IOHelper);
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
|
||||
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
|
||||
var umbracoContext = umbracoContextReference.UmbracoContext;
|
||||
|
||||
@@ -446,7 +446,8 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper);
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
|
||||
//if (setSingleton)
|
||||
//{
|
||||
|
||||
@@ -35,7 +35,8 @@ namespace Umbraco.Tests.Web
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
TestObjects.GetGlobalSettings(),
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper);
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
var r1 = new RouteData();
|
||||
r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx);
|
||||
|
||||
@@ -55,7 +56,8 @@ namespace Umbraco.Tests.Web
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
TestObjects.GetGlobalSettings(),
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper);
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
|
||||
var r1 = new RouteData();
|
||||
r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx);
|
||||
@@ -85,7 +87,8 @@ namespace Umbraco.Tests.Web
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
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
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IVariationContextAccessor _variationContextAccessor;
|
||||
private readonly UriUtility _uriUtility;
|
||||
private readonly TabsAndPropertiesMapper<IContent> _tabsAndPropertiesMapper;
|
||||
private readonly ContentSavedStateMapper<ContentPropertyDisplay> _stateMapper;
|
||||
private readonly ContentBasicSavedStateMapper<ContentPropertyBasic> _basicStateMapper;
|
||||
@@ -38,7 +39,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)
|
||||
IUserService userService, IVariationContextAccessor variationContextAccessor, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, UriUtility uriUtility)
|
||||
{
|
||||
_commonMapper = commonMapper;
|
||||
_cultureDictionary = cultureDictionary;
|
||||
@@ -52,6 +53,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
_logger = logger;
|
||||
_userService = userService;
|
||||
_variationContextAccessor = variationContextAccessor;
|
||||
_uriUtility = uriUtility;
|
||||
|
||||
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IContent>(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider);
|
||||
_stateMapper = new ContentSavedStateMapper<ContentPropertyDisplay>();
|
||||
@@ -177,7 +179,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).ToArray();
|
||||
: source.GetContentUrls(_publishedRouter, umbracoContext, _localizationService, _localizedTextService, _contentService, _variationContextAccessor, _logger, _uriUtility).ToArray();
|
||||
|
||||
return urls;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(
|
||||
@@ -284,7 +285,7 @@ namespace Umbraco.Web
|
||||
{
|
||||
return parentNodes.DescendantsOrSelf<T>(VariationContextAccessor, culture);
|
||||
}
|
||||
|
||||
|
||||
public static IEnumerable<IPublishedContent> Descendants(this IPublishedContent content, string culture = null)
|
||||
{
|
||||
return content.Descendants(VariationContextAccessor, culture);
|
||||
@@ -700,38 +701,28 @@ 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 = Composing.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 = Composing.Current.UmbracoContext;
|
||||
|
||||
if (umbracoContext == null)
|
||||
throw new InvalidOperationException("Cannot resolve a Url when Current.UmbracoContext is null.");
|
||||
if (umbracoContext.UrlProvider == null)
|
||||
throw new InvalidOperationException("Cannot resolve a Url when Current.UmbracoContext.UrlProvider is null.");
|
||||
|
||||
switch (content.ContentType.ItemType)
|
||||
{
|
||||
case PublishedItemType.Content:
|
||||
return umbracoContext.UrlProvider.GetUrl(content, mode, culture);
|
||||
if (umbracoContext == null)
|
||||
throw new InvalidOperationException("Cannot resolve a Url when Current.UmbracoContext is null.");
|
||||
|
||||
case PublishedItemType.Media:
|
||||
return umbracoContext.UrlProvider.GetMediaUrl(content, mode, culture, Constants.Conventions.Media.File);
|
||||
return content.Url(umbracoContext.UrlProvider, culture, mode);
|
||||
}
|
||||
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -209,11 +209,6 @@
|
||||
<Compile Include="PropertyEditors\RichTextEditorPastedImages.cs" />
|
||||
<Compile Include="PublishedCache\UmbracoContextPublishedSnapshotAccessor.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" />
|
||||
@@ -354,13 +349,6 @@
|
||||
<Compile Include="PropertyEditors\ValueConverters\ContentPickerValueConverter.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" />
|
||||
@@ -408,7 +396,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" />
|
||||
@@ -499,7 +486,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" />
|
||||
@@ -654,16 +640,9 @@
|
||||
<Compile Include="Mvc\UmbracoPageResult.cs" />
|
||||
<Compile Include="PropertyEditors\ValueConverters\RteMacroRenderingValueConverter.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" />
|
||||
@@ -685,24 +664,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>
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace Umbraco.Web
|
||||
{
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly UriUtility _uriUtility;
|
||||
private readonly Lazy<IPublishedSnapshot> _publishedSnapshot;
|
||||
private string _previewToken;
|
||||
private bool? _previewing;
|
||||
@@ -36,7 +37,8 @@ namespace Umbraco.Web
|
||||
IEnumerable<IMediaUrlProvider> mediaUrlProviders,
|
||||
IGlobalSettings globalSettings,
|
||||
IVariationContextAccessor variationContextAccessor,
|
||||
IIOHelper ioHelper)
|
||||
IIOHelper ioHelper,
|
||||
UriUtility uriUtility)
|
||||
{
|
||||
if (httpContext == null) throw new ArgumentNullException(nameof(httpContext));
|
||||
if (publishedSnapshotService == null) throw new ArgumentNullException(nameof(publishedSnapshotService));
|
||||
@@ -47,6 +49,7 @@ namespace Umbraco.Web
|
||||
VariationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
|
||||
_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.
|
||||
@@ -74,7 +77,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);
|
||||
UrlProvider = new UrlProvider(this, umbracoSettings.WebRouting, urlProviders, mediaUrlProviders, variationContextAccessor);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,11 +34,23 @@ namespace Umbraco.Web
|
||||
private readonly MediaUrlProviderCollection _mediaUrlProviders;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
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, IUmbracoSettingsSection umbracoSettings, IGlobalSettings globalSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IUserService userService, IIOHelper ioHelper)
|
||||
public UmbracoContextFactory(
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
IPublishedSnapshotService publishedSnapshotService,
|
||||
IVariationContextAccessor variationContextAccessor,
|
||||
IDefaultCultureAccessor defaultCultureAccessor,
|
||||
IUmbracoSettingsSection umbracoSettings,
|
||||
IGlobalSettings globalSettings,
|
||||
UrlProviderCollection urlProviders,
|
||||
MediaUrlProviderCollection mediaUrlProviders,
|
||||
IUserService userService,
|
||||
IIOHelper ioHelper,
|
||||
UriUtility uriUtility)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
|
||||
_publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService));
|
||||
@@ -51,6 +63,7 @@ namespace Umbraco.Web
|
||||
_mediaUrlProviders = mediaUrlProviders ?? throw new ArgumentNullException(nameof(mediaUrlProviders));
|
||||
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
|
||||
_ioHelper = ioHelper;
|
||||
_uriUtility = uriUtility;
|
||||
}
|
||||
|
||||
private IUmbracoContext CreateUmbracoContext(HttpContextBase httpContext)
|
||||
@@ -69,7 +82,7 @@ namespace Umbraco.Web
|
||||
|
||||
var webSecurity = new WebSecurity(httpContext, _userService, _globalSettings, _ioHelper);
|
||||
|
||||
return new UmbracoContext(httpContext, _publishedSnapshotService, webSecurity, _umbracoSettings, _urlProviders, _mediaUrlProviders, _globalSettings, _variationContextAccessor, _ioHelper);
|
||||
return new UmbracoContext(httpContext, _publishedSnapshotService, webSecurity, _umbracoSettings, _urlProviders, _mediaUrlProviders, _globalSettings, _variationContextAccessor, _ioHelper, _uriUtility);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace Umbraco.Web
|
||||
private readonly IPublishedRouter _publishedRouter;
|
||||
private readonly IUmbracoContextFactory _umbracoContextFactory;
|
||||
private readonly RoutableDocumentFilter _routableDocumentLookup;
|
||||
private readonly UriUtility _uriUtility;
|
||||
|
||||
public UmbracoInjectedModule(
|
||||
IGlobalSettings globalSettings,
|
||||
@@ -45,7 +46,8 @@ namespace Umbraco.Web
|
||||
ILogger logger,
|
||||
IPublishedRouter publishedRouter,
|
||||
IUmbracoContextFactory umbracoContextFactory,
|
||||
RoutableDocumentFilter routableDocumentLookup)
|
||||
RoutableDocumentFilter routableDocumentLookup,
|
||||
UriUtility uriUtility)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
_runtime = runtime;
|
||||
@@ -53,6 +55,7 @@ namespace Umbraco.Web
|
||||
_publishedRouter = publishedRouter;
|
||||
_umbracoContextFactory = umbracoContextFactory;
|
||||
_routableDocumentLookup = routableDocumentLookup;
|
||||
_uriUtility = uriUtility;
|
||||
}
|
||||
|
||||
#region HttpModule event handlers
|
||||
@@ -117,7 +120,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");
|
||||
@@ -206,7 +209,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
|
||||
@@ -238,7 +241,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;
|
||||
}
|
||||
@@ -426,7 +429,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));
|
||||
|
||||
DisposeHttpContextItems(httpContext);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user