Skip to content

Instantly share code, notes, and snippets.

@clausjensen
Last active April 18, 2018 14:45
Show Gist options
  • Save clausjensen/a78016de5c6b3ef2cab4f8ac13f07dc2 to your computer and use it in GitHub Desktop.
Save clausjensen/a78016de5c6b3ef2cab4f8ac13f07dc2 to your computer and use it in GitHub Desktop.
<%@ 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