Skip to content

Instantly share code, notes, and snippets.

//
// This code is referenced in the following blog posts:
// * https://colinmackay.scot/2018/08/17/ensure-controller-actions-classes-have-authorisation/
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
@sniffdk
sniffdk / ContextHelpers.cs
Last active February 28, 2022 10:03
Fake an UmbracoContext for use when doing published scheduling or other scenarios where UmbracoContext is normally null.
public class ContextHelpers
{
public static UmbracoContext EnsureUmbracoContext() {
if (UmbracoContext.Current != null)
{
return UmbracoContext.Current;
}
var httpContext = new HttpContextWrapper(HttpContext.Current ?? new HttpContext(new SimpleWorkerRequest("temp.aspx", "", new StringWriter())));
@nul800sebastiaan
nul800sebastiaan / InitContentController.cs
Created February 13, 2012 15:46
Creating a content node in Umbraco v5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Umbraco.Cms.Web.Model.BackOffice.Editors;
using Umbraco.Framework;
using Umbraco.Framework.Context;
using Umbraco.Framework.Persistence.Model;
using Umbraco.Framework.Persistence.Model.Attribution.MetaData;
using Umbraco.Framework.Persistence.Model.Constants;
@warrenbuckley
warrenbuckley / SitemapHTML.cshtml
Created February 1, 2012 17:14
Umbraco V5 Example - Sitemap HTML
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
@{
//Get the current page
var currentPage = DynamicModel;
//Will walk up the tree to the last ancestor node aka RootNode
@warrenbuckley
warrenbuckley / ListChildPagesFromCurrentPage.cshtml
Created February 1, 2012 17:01
Umbraco V5 Example - List Child Pages from Current Page
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
@* Check we have child pages *@
@if (DynamicModel.Children.Any())
{
<nav id="subnavi">
<ul>
@samandmoore
samandmoore / MacroParamValueOrDefault.cshmtl
Created January 31, 2012 14:02
Umbraco v5 MacroParameters default value
@functions {
object MacroParamValueOrDefault(dynamic paramValue, object defaultValue = null)
{
if(string.IsNullOrEmpty(paramValue)) {
return defaultValue;
} else {
return paramValue;
}
}
}
@warrenbuckley
warrenbuckley / TwitterFeed.cshtml
Created January 31, 2012 13:36
Umbraco V5 Example - Twitter Feed
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
@{
@* Macro Param: Twitter Username that defaults to umbraco if empty *@
var twitterUsername = String.IsNullOrEmpty(Model.MacroParameters.twitterUsername) ? "umbracoproject" : Model.MacroParameters.twitterUsername;
@warrenbuckley
warrenbuckley / FetchRemoteRSS
Created January 31, 2012 12:17
Umbraco V5 Example - Fetch Remote RSS
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web.Macros
@* Added these in *@
@using System.ServiceModel.Syndication
@using System.Xml;
@{
// Get the remote url
var remoteUrl = String.IsNullOrEmpty(Model.MacroParameters.remoteURL) ? "http://feeds.feedburner.com/umbracoblog" : Model.MacroParameters.remoteURL;
@warrenbuckley
warrenbuckley / MediaUploadProperty.cshtml
Created January 31, 2012 11:05
Umbraco V5 Example - Media Upload Property
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
@{
//Output an image from an upload property on current doctype
//Property alias of upload field
var uploadPropAlias = String.IsNullOrEmpty(Model.MacroParameters.uploadPropAlias) ? "myUploadPropertyAlias" : Model.MacroParameters.uploadPropAlias;
@warrenbuckley
warrenbuckley / ListItemsFromMediaFolder.cshtml
Created January 30, 2012 21:28
Umbraco V5 Example - Media Picker List Images from Folder
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
@{
//Output an image from the media picker
//Property alias of mediaPicker