Skip to content

Instantly share code, notes, and snippets.

View AaronSadlerUK's full-sized avatar

Aaron AaronSadlerUK

View GitHub Profile
@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;
@AaronSadlerUK
AaronSadlerUK / HeaderPolicyCollection.cs
Last active December 2, 2021 18:05
Configuring HTTP Security Headers In Umbraco V9
public static HeaderPolicyCollection GetHeaderPolicyCollection(bool isDev)
{
var policy = new HeaderPolicyCollection()
.AddFrameOptionsDeny()
.AddXssProtectionBlock()
.AddContentTypeOptionsNoSniff()
.AddReferrerPolicyStrictOriginWhenCrossOrigin()
.RemoveServerHeader()
.AddCrossOriginOpenerPolicy(builder =>
{
@AaronSadlerUK
AaronSadlerUK / ISiteMapXmlService.cs
Created October 13, 2021 09:55
How to create an Xml Sitemap in Umbraco V9
public interface ISiteMapXmlService
{
public string GenerateXml();
}
@AaronSadlerUK
AaronSadlerUK / ISyndicationXmlService.cs
Last active October 27, 2021 14:54
How to create an RSS & Atom feed in Umbraco V9
using System.ServiceModel.Syndication;
public interface ISyndicationXmlService
{
Atom10FeedFormatter GenerateAtomXml(string feedTitle, string feedDescription);
Rss20FeedFormatter GenerateRssXml(string feedTitle, string feedDescription);
}
@AaronSadlerUK
AaronSadlerUK / bundleconfig.json
Created October 6, 2021 20:18
How to use bundling and minification with Umbraco V9 (Part 2)
[
{
"outputFileName": "wwwroot/bundles/site.min.css",
"inputFiles": [
"wwwroot/lib/bootstrap/dist/css/bootstrap.css",
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/bundles/site.min.js",
@AaronSadlerUK
AaronSadlerUK / bundleconfig.json
Created October 6, 2021 18:40
How to use bundling and minification with Umbraco V9
[
{
"outputFileName": "wwwroot/css/site.min.css",
"inputFiles": [
"wwwroot/lib/bootstrap/dist/css/bootstrap.css",
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/js/site.min.js",
@AaronSadlerUK
AaronSadlerUK / MemberAuthenticationSurfaceController.cs
Last active August 31, 2022 03:05
How to create member login and logout form in Umbraco V9 (RC)
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Logging;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Web.Common.Models;
@AaronSadlerUK
AaronSadlerUK / IndexHelperComposer.cs
Created August 7, 2021 18:52
How to create a custom index in Umbraco V9
using Examine;
using Microsoft.Extensions.DependencyInjection;
using UmbHost.Core.Components;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Infrastructure.Examine;
namespace UmbHost.Core.Composers
{
public class IndexHelperComposer : IUserComposer
@AaronSadlerUK
AaronSadlerUK / umbraco-forms-ajax.js
Last active May 5, 2022 11:30
Umbraco Forms (Single Page) submit within bootstrap modal using ajax
// jQuery plugin to prevent double submission of forms
jQuery.fn.preventDoubleSubmission = function () {
$(this).on('submit', function (e) {
e.preventDefault();
var modal = $(this);
var $form = $(this).children('form').first();
if ($form.data('submitted') === true) {
// Previously submitted - don't submit again
@AaronSadlerUK
AaronSadlerUK / AnySurfaceController.cs
Last active May 18, 2021 11:19
hCaptcha Service for use with a Surface Controller or any MVC Controller (With light modifications)
public class AnySurfaceController : SurfaceController
{
private readonly IhCaptchaService _hCaptchaService;
public AnySurfaceController(IhCaptchaService hCaptchaService)
{
_hCaptchaService = hCaptchaService;
}
[ValidateAntiForgeryToken]
[HttpPost]