Skip to content

Instantly share code, notes, and snippets.

@clausjensen

clausjensen/Code.ashx

Last active Apr 18, 2018
Embed
What would you like to do?
<%@ WebHandler Language="C#" Class="Code" %>
using System;
using System.Web;
using Umbraco.Web;
public class Code : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
// Getting an Umbraco context to work with
var umbracoContext = UmbracoContext.Current;
// and an UmbracoHelper
var umbracoHelper = new UmbracoHelper(umbracoContext);
// Getting content
var content = umbracoHelper.TypedContentAtRoot();
foreach (var c in content)
{
context.Response.Write(c.Name + Environment.NewLine);
}
// Getting a value of a property
//var propertyValue = content.GetPropertyValue<string>("metaTitle");
// Writing out a value for debugging purposes
//context.Response.Write("Property value: " + propertyValue + Environment.NewLine);
// Getting the Umbraco services
var services = umbracoContext.Application.Services;
// Get a datatype by alias
var datatype = services.DataTypeService.GetDataTypeDefinitionByName("Textstring");
// Writing out the ID of this datatype for debugging purposes
context.Response.Write("Datatype ID: " + datatype.Id + Environment.NewLine);
}
public bool IsReusable
{
get
{
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment