Skip to content

Instantly share code, notes, and snippets.

View alindgren's full-sized avatar
💭
I may be slow to respond.

Alex Lindgren alindgren

💭
I may be slow to respond.
View GitHub Profile
@alindgren
alindgren / web.config
Created September 29, 2016 15:37
Canonical Domain Redirect
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.domain\.com$" negate="true" />
</conditions>
@alindgren
alindgren / ContentExtensions.cs
Last active October 11, 2017 17:30
Umbraco Content SetValueByPreValue and SetValuesByPreValues extension methods
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
namespace My.Umbraco.Extensions
{
public static class ContentExtensions
{
/// <summary>
/// Sets the value of a property to the PreValue ID for a given preValue.
let AWS = require('aws-sdk');
let sqs = new AWS.SQS();
let Airtable = require('airtable');
let base = new Airtable({apiKey: 'keyql7soeJgu7cdsP'}).base('appJdKhgVuGZUv0va');
exports.handler = (event, context, callback) => {
sqs.receiveMessage({
QueueUrl: 'https://sqs.us-west-2.amazonaws.com/852229429830/FundraiseDonations',
AttributeNames: ['All'],
@alindgren
alindgren / Readme.md
Created December 2, 2016 17:20
Canonical Domain Redirect for Azure App Service deployment slots

I often create a canonical host name URL Rewrite rule for a production site so that requests redirect to a single domain -- for example from alexlindgren.com to www.alexlindgren.com. For sites hosted with Azure App Service using deployment slots, we only want the production slot to redirect, otherwise going to the staging slot will redirect you to production since each slot uses uses the same web.config. To handle this, one can just add the non production domains to the conditions as seen in this gist.

@alindgren
alindgren / MultilingualContentFinder.cs
Last active August 13, 2018 15:24
ContentFinder for multilingual sites in Umbraco
using System;
using System.Globalization;
using System.Web;
using Umbraco.Web.Routing;
using Umbraco.Core;
public class MultilingualContentFinder : IContentFinder
{
public bool TryFindContent(PublishedContentRequest contentRequest)
{
@alindgren
alindgren / deploy.cmd
Created December 18, 2017 02:22
Azure AppService deployment node-based build script
@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off
:: ----------------------
:: KUDU Deployment Script
:: Version: 1.0.15
:: ----------------------
:: Prerequisites
:: -------------
@alindgren
alindgren / XMLSitemap.cshtml
Last active May 15, 2020 17:42
XML sitemap for Umbraco 7 (based on Cultiv Search Engine Sitemap package). See http://www.alexlindgren.com/archive/dynamically-generated-xml-sitemaps-with-umbraco-7/
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using System.Linq;
@{
Layout = null;
Response.ContentType = "text/xml";
}<?xml version='1.0' encoding='UTF-8' ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
@ListChildNodes(Umbraco.TypedContent(UmbracoContext.Current.PageId).AncestorOrSelf(1))
@alindgren
alindgren / Readme.md
Created January 17, 2017 15:28
Powershell script for grabbing Umbraco Cloud database locally

Notes

Umbraco Cloud uses SQL Azure in the cloud, but for local environments it normally pulls the data down to a local SQL CE database using 'dark magic.' You can, however, pull down the Dev database and restore it to a local SQL Server install. For this, use database.ps1 PowerShell script. You may need to Set-ExecutionPolicy RemoteSigned to run the script. If you are using Windows 7, you may need to configure powershell to use .NET 4 (see http://tfl09.blogspot.com/2010/08/using-newer-versions-of-net-with.html).

In the script, set the location of the folder where you want the DB bacpac file to get saved. Once the file is saved, in SQL Server Management Studio 2014 in the Object Explorer, right click