Skip to content

Instantly share code, notes, and snippets.

@elmogallen
Created July 11, 2014 13:30
Show Gist options
  • Save elmogallen/0de21afc4eafaddab5c1 to your computer and use it in GitHub Desktop.
Save elmogallen/0de21afc4eafaddab5c1 to your computer and use it in GitHub Desktop.
Adding Web API to Kentico 7 (ASP.NET)
/// *******************************************************************************************************************
/// **** THIS IS AN EXCERPT; I'M ONLY SHOWING RELEVANT PARTS OF THIS FILE, ALONG WITH NOTES ON HOW TO MAKE IT WORK ****
/// *******************************************************************************************************************
/// Mostly based on info found here: http://devnet.kentico.com/forums/f68/fp12/t34518/using-web-api-with-kentico
/// NOTE: The following DLLs seemed to be necessary for this to work properly and not blow up Kentico:
/// Newtonsoft.Json.dll
/// System.Net.Http.dll
/// System.Net.Http.Formatting.dll
/// System.Net.Http.WebRequest.dll
/// System.Web.Http.WebHost.dll
/// Go into Site Manager and exclude the URL to your /api path. There is *no* actual /api folder
/// in the file system, and you don't want Kentico trying to rewrite it.
/// After you make the changes below, you can add a controller anywhere in your App_Code folder.
/// I created a Controllers folder underneath App_Code, then added a New Item > Web API Controller.
using System.Web.Http;
using System.Web.Routing;
/// <summary>
/// Application start event handler.
/// </summary>
public void Application_Start(object sender, EventArgs e)
{
// Azure Application start init
AzureInit.Current.ApplicationStartInit();
CMSAppBase.CMSApplicationStart();
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment