Skip to content

Instantly share code, notes, and snippets.

@digitalParkour
digitalParkour / XConnectService.cs
Last active December 12, 2019 17:36
Sitecore XConnectService extension
namespace Sitecore.Foundation.SitecoreExtensions.Services
{
using Sitecore.Diagnostics;
using Sitecore.Foundation.DependencyInjection;
using Sitecore.XConnect;
using Sitecore.XConnect.Client;
using System;
using System.Linq;
/// <summary>
@digitalParkour
digitalParkour / Foundation.Optimizations.config
Last active February 26, 2018 20:40
Sitecore Placeholder Toggle Snippets
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<!-- :: Only applicable to CA environments :: -->
<!-- this skips placeholder (Header and Footer) in EE but can be toggled back on with a button in the EE ribbon -->
<sitecore>
<pipelines>
<mvc.renderPlaceholder>
<!-- Patch to be first processor -->
<processor type="Community.Foundation.Optimizations.Pipelines.MvcRenderPlaceholder.SkipPlaceholdersByUserSetting, Community.Foundation.Optimizations"
patch:before="*[1]"/>
namespace Community.Foundation.Mvc
{
using System.Reflection;
using System.Web.Mvc;
/// <summary>
/// Mechanism to handle multiple sitecore form renderings on a page
/// When one is posted, all receive the post verb
/// Mark all with this attribute and it will revert to the Get method when its form is not the real one being called.
/// Example:
@using Community.Foundation.Mvc
@model ExampleModel
<div class="component">
<p>Form B</p>
<form method="post">
@Html.MultiformPostProtection() <!-- Becomes: <input type="hidden" name="__FormToken" value="FormB" /> -->
@Html.AntiForgeryToken()
<input type="submit"/>
</form>
</div>
@using Community.Foundation.Mvc
@model ExampleModel
<div class="component">
<p>Form A</p>
<form method="post">
@Html.MultiformPostProtection()<!-- Becomes: <input type="hidden" name="__FormToken" value="FormA" /> -->
@Html.AntiForgeryToken()
<input type="submit"/>
</form>
</div>
[HttpGet]
public ActionResult FormA()
{
var model = _example.GetModel();
return PartialView(model);
}
[HttpPost]
[MultiformPostProtection] /* Verifies form token matches this action, Form A, otherwise returns FormA() */
[ValidateAntiForgeryToken]
public ActionResult FormA(ExampleModel model)