Skip to content

Instantly share code, notes, and snippets.

Erik Henningson ErikHen

Block or report user

Report or block ErikHen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View DefaultPageController.cs
namespace AlloyDemo.Controllers
{
[TemplateDescriptor(Inherited = true)]
public class DefaultPageController : PageControllerBase<SitePageData>
{
[EditableContentOutputCache]
public ViewResult Index(SitePageData currentPage)
{
var model = CreateModel(currentPage);
return View($"~/Views/{currentPage.GetOriginalType().Name}/Index.cshtml", model);
View SitePageData.cs
namespace AlloyDemo.Models.Pages
{
public abstract class SitePageData : PageData, ICustomCssInContentArea, IDisableOutputCache
{
[Display(Name = "Disable output cache", GroupName = SystemTabNames.Settings, Order = 500)]
public virtual bool? DisableOutputCache { get; set; }
...
View EditableContentOutputCacheAttribute.cs
namespace AlloyDemo.Business
{
public sealed class EditableContentOutputCacheAttribute : ContentOutputCacheAttribute
{
public EditableContentOutputCacheAttribute()
{
UseOutputCacheValidator = UseOutputCache;
}
private static bool UseOutputCache(IPrincipal principal, HttpContextBase context, TimeSpan duration)
View IDisableOutputCache.cs
namespace AlloyDemo.Business
{
public interface IDisableOutputCache
{
bool? DisableOutputCache { get; set; }
}
}
@ErikHen
ErikHen / ScaleDownResources
Created Apr 3, 2019
Azure Automation Powershell Runbook that scales Azure resources
View ScaleDownResources
.\LoginToAzure.ps1
#scale down web app to "D1 Shared"
Set-AzureRmAppServicePlan -Name "<your sesrvice plan name>" -ResourceGroupName "<your resource group name>" -Tier Shared
#scale down database to "B1 Basic"
Set-AzureRmSqlDatabase -ResourceGroupName "<your resource group name>" -ServerName "<sql server name>" -DatabaseName "<database name>" -Edition Basic
#scale a web app to "B2 Basic"
#Set-AzureRmAppServicePlan -Name "<your sesrvice plan name>" -ResourceGroupName "<your resource group name>" -Tier Basic -WorkerSize Medium
@ErikHen
ErikHen / LoginToAzure
Created Apr 3, 2019
Azure Automation Powershell Runbook that logs in to Azure
View LoginToAzure
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
View ImageTypes.cs
using ImageProcessor.Web.Episerver;
namespace PictureDemo.Business.Rendering
{
public static class ImageTypes
{
// A full width Hero image is very simple, since its always 100% of the viewport width.
public static ImageType HeroImage = new ImageType
{
DefaultImgWidth = 1280,
View PictureHelper.cs
using MyEpiSite.Business.Rendering;
using System;
using System.Configuration;
using System.Web;
using System.Web.Mvc;
namespace MyEpiSite.Helpers
{
public static class PictureHelper
{
View ImageTypes.cs
namespace MyEpiSite.Business.Rendering
{
public class ImageType
{
public int? DefaultImgWidth { get; set; } //this size will be used in browsers that don't support the picture element
public int[] SrcSetWidths { get; set; } // the different image widths you want the browser to select from
public string[] SrcSetSizes { get; set; }
public double HeightRatio { get; set; }
public int Quality { get; set; }
View PictureHelper.cs
using MyEpiSite.Business.Rendering;
using System.Configuration;
using System.Web;
using System.Web.Mvc;
namespace MyEpiSite.Helpers
{
public static class PictureHelper
{
public static IHtmlString Picture(this HtmlHelper helper, string imageUrl, ImageType imageType, string cssClass = "")
You can’t perform that action at this time.