Skip to content

Instantly share code, notes, and snippets.

View AaronSadlerUK's full-sized avatar

Aaron AaronSadlerUK

View GitHub Profile
@AaronSadlerUK
AaronSadlerUK / HomePageUrlProvider.cs
Last active November 11, 2024 21:28
UrlProvider to remove /home/ from published Urls in Umbraco V13
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Web;
public class HomePageUrlProvider : DefaultUrlProvider
{
@AaronSadlerUK
AaronSadlerUK / delete-umbraco-logs-90days.ps1
Created May 9, 2024 16:35
PowerShell scheduled task to automatically delete Umbraco log files older than 90days
# Set the directory path where you want to search
$directory = "E:\\"
# Get files matching the specified pattern and older than 90 days
$files = Get-ChildItem -Path $directory -Filter "UmbracoTraceLog*" -Recurse | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-90) }
$count = $files.Count
Write-Host "Number of files found: $count"
@AaronSadlerUK
AaronSadlerUK / script.sql
Last active April 29, 2024 19:29
Update Umbraco.Dropdown and Umbraco.DropDownMultiple to Umbraco.DropDown.Flexible
select * from cmsDataType where nodeId = ID
update cmsDataType set propertyEditorAlias = 'Umbraco.DropDown.Flexible' where nodeId = ID
select * from cmsDataTypePreValues where datatypeNodeId = ID
insert into cmsDataTypePreValues (alias, sortorder, [value], datatypeNodeId) values ('multiple', 7, '0', ID)
DECLARE @AlterStatements TABLE (
Statement NVARCHAR(MAX)
)
INSERT INTO @AlterStatements (Statement)
SELECT 'ALTER INDEX [' + I.name + '] ON [' + T.name + '] REBUILD'
FROM sys.indexes I
INNER JOIN sys.tables T ON I.object_id = T.object_id
WHERE I.type_desc = 'NONCLUSTERED'
AND I.name IS NOT NULL
@AaronSadlerUK
AaronSadlerUK / view.cshtml
Created October 13, 2023 13:17
Google Tag Manager Nonce
<script id="gtmScript" data-nonce="@Html.CspScriptNonceValue()">
(function (w, d, s, l, i) {
w[l] = w[l] || []; w[l].push({
'gtm.start':
new Date().getTime(), event: 'gtm.js'
}); var f = d.getElementsByTagName(s)[0],
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src =
'https://www.googletagmanager.com/gtm.js?id=' + i + dl; var n = d.querySelector('[nonce]');
n && j.setAttribute('nonce', n.nonce || n.getAttribute('nonce')); f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', '###-#######');</script>
@AaronSadlerUK
AaronSadlerUK / IntFriendlyMediaPickerValueConverter.cs
Created August 2, 2023 09:14
IntFriendlyMediaPickerValueConverter
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.PropertyEditors.ValueConverters;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Services;
public class IntFriendlyMediaPickerValueConverter : MediaPickerValueConverter
{
@AaronSadlerUK
AaronSadlerUK / default.aspx
Created December 14, 2022 16:56
Output Headers
<%@ Page Language="vb" %>
<html>
<head>
<title>Showing HTTP Headers via the Headers Collection in ASP.NET</title>
</head>
<body>
<%
Dim AllHttp As String
@AaronSadlerUK
AaronSadlerUK / Command
Created November 20, 2022 14:55
Auto update WMSVC Certificate after Win-Acme runs
.\wacs.exe --installation script --script "Scripts\ImportWMSVC.ps1" --scriptparameters "'{CertThumbprint}'" --certificatestore My
@AaronSadlerUK
AaronSadlerUK / IValidateYubiKeyOTPService.cs
Last active August 29, 2022 11:23
YubiKey OTP - Umbraco V10
public interface IValidateYubiKeyOTPService
{
Task<bool> ValidateYubiKey(string otp);
}
@AaronSadlerUK
AaronSadlerUK / WebPMiddleware.cs
Last active July 5, 2022 14:04
Dynamic WebP Images in Umbraco V10
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
public class WebPMiddleware
{
private readonly RequestDelegate _next;