Skip to content

Instantly share code, notes, and snippets.

@leekelleher
Created October 18, 2016 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leekelleher/3bab3b17dc9e3115306c9851a84e80f0 to your computer and use it in GitHub Desktop.
Save leekelleher/3bab3b17dc9e3115306c9851a84e80f0 to your computer and use it in GitHub Desktop.
A QueryString processor for Ditto
using System.Web;
using Umbraco.Core;
namespace Our.Umbraco.Ditto
{
public class QueryStringAttribute : DittoProcessorAttribute
{
public QueryStringAttribute(string key)
: this()
{
Key = key;
}
public QueryStringAttribute()
{ }
public string Key { get; set; }
public override object ProcessValue()
{
var qs = HttpContext.Current?.Request?.QueryString;
if (qs == null)
return null;
var propertyName = this.Context.PropertyDescriptor != null
? Context.PropertyDescriptor.Name
: string.Empty;
var key = Key ?? propertyName;
return qs.AllKeys.InvariantContains(key)
? qs.Get(key)
: null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment