Instantly share code, notes, and snippets.

View BaseController.cs
public virtual Tuple<string, string> GetAdaptiveImageUrls(Item item, string imageFieldName, int maxWidth = 300)
{
Assert.IsNotNull(item, nameof(item));
Assert.IsNotNullOrEmpty(imageFieldName, nameof(imageFieldName));
ImageField imageField = item.Fields[imageFieldName];
if (imageField?.MediaItem != null /*&& imageField.MediaItem.Versions.Count > 0*/)
{
string imageUrl = HashingUtils.ProtectAssetUrl(MediaManager.GetMediaUrl(imageField.MediaItem, new MediaUrlOptions {MaxWidth = maxWidth}));
View gist:519dee612ca4683a18303298a429715c
using System.Web.Mvc;
using Castle.Windsor;
using Sitecore.Mvc.Controllers;
using Sitecore.Mvc.Pipelines.Loader;
using Sitecore.Pipelines;
using Interfaces.Managers.Windsor;
using ControllerBuilder = System.Web.Mvc.ControllerBuilder;
namespace Website
{
View RenderItem.cs
public virtual HtmlString RenderItem(Item item, string controller, string action)
{
Assert.ArgumentNotNull(item, "item");
Assert.ArgumentNotNullOrEmpty(controller, "controller");
Assert.ArgumentNotNullOrEmpty(action, "action");
var r = new Rendering();
r.DataSource = item.Paths.FullPath;
using (RenderingContext.EnterContext(r))
{
View PerformanceMeasurementProcessorBegin.cs
using System.Diagnostics;
using System.Web;
using Sitecore.Mvc.Pipelines.Response.RenderRendering;
namespace Website.Pipelines.RenderRendering
{
public class PerformanceMeasurementProcessorBegin : RenderRenderingProcessor
{
public override void Process(RenderRenderingArgs args)
{
View SetupIoc.config
<?xml version="1.0"?>
<configuration>
<sitecore>
<pipelines>
<initialize>
<processor type="Website.SetupIoc, Website" />
</initialize>
</pipelines>
</sitecore>
</configuration>