Skip to content

Instantly share code, notes, and snippets.

Avatar

Kieron McIntyre digbyswift

View GitHub Profile
@digbyswift
digbyswift / umbraco-publishedcontent-extensions-root.cs
Last active Aug 29, 2015
Find the root node of the website content branch
View umbraco-publishedcontent-extensions-root.cs
public static IPublishedContent Root(this IPublishedContent content)
{
var root = (IPublishedContent)HttpContext.Current.Items["Content.Root"];
if (root == null)
{
root = content.Ancestor(1)
.Siblings()
.First(x => x.DocumentTypeAlias == DocumentTypeAliases.Website);
View urlrewrite-umbraco-hide-default-login
<rule name="Restrict umbraco access" stopProcessing="true">
<match url="^umbraco/?.*"/>
<action type="CustomResponse" statusCode="404" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.example.co.uk$"/>
<add input="{REQUEST_URI}" pattern="^umbraco/Surface/.*" negate="true" ignoreCase="true" />
</conditions>
</rule>
View urlrewrite-non-www-redirect
<rule name="Redirect Non WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www|bo-admin)(.*)$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://www.{C:1}/{R:0}" />
</rule>
@digbyswift
digbyswift / umbraco-rendermvccontroller-default-action
Last active Oct 17, 2015
Default Umbraco RenderMvcController action
View umbraco-rendermvccontroller-default-action
public class HomeController : RenderMvcController
{
public override ActionResult Index(RenderModel model)
{
return CurrentTemplate(model);
}
}
View umbraco-rendermvccontroller-custom-index-action
public ActionResult Index(RenderModel model, FormCollection form)
{
return CurrentTemplate(model);
}
View umbraco-rendermvccontroller-failing-async-index-action
public async Task<ActionResult> Index(RenderModel model, FormCollection form)
{
await Task.Delay(1000);
return CurrentTemplate(model);
}
View umbraco-surfacecontroller-async-action
[HttpPost]
public async Task<ActionResult> SubmitForm(string postcode)
{
// Do something async with the postcode
return CurrentUmbracoPage();
}
View umbraco-rendermvccontroller-async-template-action
public async Task<ActionResult> Home(RenderModel model)
{
return CurrentTemplate(model);
}
View umbraco-rendermvccontroller-extended-async-template-action
public async Task<ActionResult> Home(RenderModel model, int? page, string query)
{
return CurrentTemplate(model);
}
View umbraco-customcontrollerfactory
public class CustomControllerFactory : RenderControllerFactory
{
public override IController CreateController(RequestContext requestContext, string controllerName)
{
var controllerInstance = base.CreateController(requestContext, controllerName) as Controller;
if (controllerInstance != null)
{
controllerInstance.ActionInvoker = new CustomActionInvoker();
}
You can’t perform that action at this time.