Created
May 3, 2014 02:58
-
-
Save kamsar/d7f47ff20e59d8fdd4f5 to your computer and use it in GitHub Desktop.
Sitecore Web API registration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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