SHARE
TWEET

Untitled

a guest Jan 12th, 2017 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Net.Http.Formatting;
  3. using System.Web.Http;
  4.  
  5. namespace Feature.DataAPI
  6. {
  7.     public static class WebApiConfig
  8.     {
  9.         public static void Register(HttpConfiguration config)
  10.         {
  11.             // Web API configuration and services
  12.  
  13.             // This block of code sets the application to emit json globally by default
  14.             GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(
  15.                 new RequestHeaderMapping("Accept", "text/html", StringComparison.InvariantCultureIgnoreCase, true,
  16.                     "application/json"));
  17.         }
  18.     }
  19. }
  20.    
  21. using System.Web.Http;
  22.  
  23. namespace Feature.DataAPI
  24. {
  25.     public class WebApiApplication : System.Web.HttpApplication
  26.     {
  27.         protected void Application_Start()
  28.         {
  29.             GlobalConfiguration.Configure(WebApiConfig.Register);
  30.  
  31.             // This block of code is to handle a circular reference error when serializing the json output
  32.             GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling =
  33.                 Newtonsoft.Json.ReferenceLoopHandling.Ignore;
  34.  
  35.             GlobalConfiguration.Configuration.EnsureInitialized();
  36.         }
  37.     }
  38. }
  39.    
  40. using Sitecore.Pipelines;
  41. using System.Web.Http;
  42. using System.Web.Http.Routing;
  43.  
  44. namespace Feature.DataAPI.Pipelines
  45. {    
  46.     public class RegisterRoutes
  47.     {
  48.         public void Process(PipelineArgs args)
  49.         {
  50.             GlobalConfiguration.Configure(Configure);
  51.         }
  52.  
  53.         private static void Configure(HttpConfiguration configuration)
  54.         {  
  55.             configuration.Routes.Add("API", new HttpRoute("sitecore/api/{controller}/{id}"));
  56.         }
  57.     }
  58. }
  59.    
  60. <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  61.   <sitecore>
  62.     <pipelines>
  63.       <initialize>
  64.         <processor type="Feature.DataAPI.Pipelines.RegisterRoutes,Feature.DataAPI" patch:after="processor[@type='Sitecore.Pipelines.Loader.EnsureAnonymousUsers, Sitecore.Kernel']" />
  65.       </initialize>
  66.     </pipelines>
  67.   </sitecore>
  68. </configuration>
RAW Paste Data
Challenge yourself this year...
Learn something new in 2017
Top