Skip to content

Instantly share code, notes, and snippets.

@kamsar
Created May 3, 2014 02:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kamsar/d7f47ff20e59d8fdd4f5 to your computer and use it in GitHub Desktop.
Save kamsar/d7f47ff20e59d8fdd4f5 to your computer and use it in GitHub Desktop.
Sitecore Web API registration
using System.Net.Http.Formatting;
using System.Web.Http;
using Foo.Web;
// automatically exectute this class' Start() method right after Application_Start (without needing to change global.asax)
[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(WebApiConfig), "Start")]
namespace Foo.Web
{
public static class WebApiConfig
{
public static void Start()
{
GlobalConfiguration.Configure(Register);
}
public static void Register(HttpConfiguration config)
{
// initialize and map all attribute routed Web API controllers (note: this does not enable MVC attribute routing)
config.MapHttpAttributeRoutes();
// force JSON responses only (no XML)
config.Formatters.Clear();
config.Formatters.Add(new JsonMediaTypeFormatter());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment