Skip to content

Instantly share code, notes, and snippets.

@VesselinVassilev
Last active March 19, 2018 05:43
Show Gist options
  • Save VesselinVassilev/43d134220bfce38568025e536ea02c03 to your computer and use it in GitHub Desktop.
Save VesselinVassilev/43d134220bfce38568025e536ea02c03 to your computer and use it in GitHub Desktop.
Sitefinity - Custom WebService
[HttpGet]
public HttpResponseMessage GetPromos()
{
if (ClaimsManager.GetCurrentUserId() == Guid.Empty)
{
throw new Exception("You need to authenticate first");
}
var manager = DynamicModuleManager.GetManager();
var promos = manager.GetLiveDataItemsForType(ScootConstants.CountryPromotion_DynamicType)
.ToListOf<PromoGroup>();
return Request.CreateResponse(HttpStatusCode.OK, new { Result = ScootConstants.Success, Data = promos });
}
protected void Application_Start(object sender, EventArgs e)
{
SystemManager.ApplicationStart += SystemManager_ApplicationStart;
}
private void SystemManager_ApplicationStart(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
private void RegisterRoutes(RouteCollection routes)
{
routes.Ignore("{resource}.axd/{*pathInfo}");
// register a custom route /ajax/ for custom webservices
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "ajax/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment