Last active
April 22, 2021 09:49
-
-
Save elucidan/9a0cda4d615ef4fcc1b1d99bc5d3ecf0 to your computer and use it in GitHub Desktop.
Class to enable umbraco mini profiler on every request, bit hacky and doesn't handle multiple query strings yet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace YourNamespace.Core | |
{ | |
using System; | |
using System.Collections.Generic; | |
using Umbraco.Core.Configuration; | |
using Umbraco.Core.Configuration.UmbracoSettings; | |
using Umbraco.Core.Logging; | |
using Umbraco.Core.Models.PublishedContent; | |
using Umbraco.Web; | |
using Umbraco.Web.Routing; | |
using Umbraco.Core.Composing; | |
public class DebugUrlProvider : DefaultUrlProvider | |
{ | |
public override UrlInfo GetUrl(UmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, | |
string culture, Uri current) | |
{ | |
UrlInfo defaultUrlInfo = base.GetUrl(umbracoContext, content, mode, culture, current); | |
if (!defaultUrlInfo.IsUrl) | |
{ | |
return defaultUrlInfo; | |
} | |
if (System.Configuration.ConfigurationManager.AppSettings["UseProfilerOnAllPages"] == "true") | |
{ | |
var originalUrl = defaultUrlInfo.Text; | |
var customUrl = $"{originalUrl}{(originalUrl.Contains("?") ? "&":"?")}umbDebug=true"; | |
return new UrlInfo(customUrl, true, defaultUrlInfo.Culture); | |
} | |
return base.GetUrl(umbracoContext, content, mode, culture, current); | |
} | |
public DebugUrlProvider(IRequestHandlerSection requestSettings, ILogger logger, IGlobalSettings globalSettings, | |
ISiteDomainHelper siteDomainHelper) : base(requestSettings, logger, globalSettings, siteDomainHelper) | |
{ | |
} | |
} | |
public class RegisterCustomUrlProviderComposer : IUserComposer | |
{ | |
public void Compose(Composition composition) | |
{ | |
composition.UrlProviders().Insert<DebugUrlProvider>(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- add this to your app settings --> | |
<add key="UseProfilerOnAllPages" value="true" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good shout, updated it