Skip to content

Instantly share code, notes, and snippets.

@contensis
Created March 31, 2015 13:38
Show Gist options
  • Save contensis/40d0a61f63e2de489281 to your computer and use it in GitHub Desktop.
Save contensis/40d0a61f63e2de489281 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using CMS_API.WebHooks;
using Contensis.Framework.Web.Controllers;
namespace [YourNamespace]
{
[RoutePrefix("api/custom/webhook")]
public class WebHookController : ContensisApiController
{
/// <summary>
/// The web hook response list, held statically so our Razor View can reference it
/// </summary>
public static List<WebHookResponse> WebHookResponseList = new List<WebHookResponse>();
/// <summary>
/// The endpoint for this Webhook example
/// </summary>
/// <param name="data">The data.</param>
/// <returns></returns>
[HttpPost]
[Route("SampleEndPoint")]
public HttpResponseMessage SampleEndPoint(WebHookResponse data)
{
// Given the class RoutePrefix, and the method attribute Route
// then a Global Setting, or CMS Config setting of:
// http://[yourwebsitesname]/api/custom/webhook/SampleEndPoint would
// be routed to this ApiController
// We would actually do something more useful, maybe based on the Event type
// but for the purposes of this example, we do the same thing regardless
switch (data.EventType)
{
case "Security.User.Register":
WebHookResponseList.Add(data);
break;
case "Security.User.Login":
WebHookResponseList.Add(data);
break;
case "Security.User.Logoff":
WebHookResponseList.Add(data);
break;
case "Security.User.Update":
WebHookResponseList.Add(data);
break;
}
// Webhooks are fired asynchronously, and anything other than
// a Http Status 200, will just log the response, but wont hold
// up execution of the CMS nor your website.
return new HttpResponseMessage(HttpStatusCode.OK);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment