Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using System.Web;
using System.Web.UI;
using Telerik.Sitefinity.Abstractions;
using Telerik.Sitefinity.Mvc;
using Telerik.Sitefinity.Mvc.Proxy;
using Telerik.Sitefinity.Services;
@avisra
avisra / CustomPageRouteHandler.cs
Last active August 18, 2016 23:12
Custom page route handler for improved OutputCache
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.Sitefinity.Abstractions;
using Telerik.Sitefinity.Web;
using Telerik.Microsoft.Practices.Unity;
using System.Collections.Specialized;
namespace SitefinityWebApp
@avisra
avisra / Global.asax.cs
Created April 13, 2013 05:08
This snippet allows you to redirect users to a specific page when they try to access a page they are not authorized to access.
namespace SitefinityWebApp
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
Bootstrapper.Initialized += new EventHandler<ExecutedEventArgs>(Bootstrapper_Initialized);
}
protected void Bootstrapper_Initialized(object sender, ExecutedEventArgs e)
@avisra
avisra / DynamicTypes.cs
Created April 13, 2013 04:53
This snippet demonstrates how to extend one of Sitefinity's classes (like Discount) to support dynamic fields.
// If this class is not already setup as a dynamic meta type - set it up. Without this, you cannot add custom fields to the type
if (metaManager.GetMetaType(typeof(Discount)) == null)
{
metaManager.CreateMetaType(typeof(Discount));
metaManager.SaveChanges();
}
// The snippet below allows you to create a new property/field of the specified type (Discount). The benefit to this is that Sitefinity will actually create a new column for "Uses" and this can be saved/read using Sitefinity's functions: discountObject.GetValue<decimal>("Uses") and discountObject.SetValue("Uses", 1)
App.WorkWith()
@avisra
avisra / CustomFormsControl.cs
Created April 13, 2013 04:37
Sitefinity's Form Builder allows users to create forms on the fly. This code snippet is for overriding the default control for Form Builder forms. This allows you to attach to the save event of the form so that you can process data when the form is submitted. This works well for instances where you need to capture lead data for sending to a CRM.
public class CustomFormsControl : FormsControl
{
protected override void InitializeControls(GenericContainer container)
{
base.InitializeControls(container);
// Attaches to the FormSaved event to run custom code upon submitting a Form Builder form.
this.FormSaved += new EventHandler<System.EventArgs>(CustomFormsControl_FormSaved);
}