Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Azure Event grid - Custom event handler
public async Task<IActionResult> Post([FromBody]object request)
{
try
{
var eventGridEvent = JsonConvert.DeserializeObject<EventGridEvent[]>(request.ToString());
foreach (var item in eventGridEvent)
{
if (string.Equals(item.EventType, "Microsoft.EventGrid.SubscriptionValidationEvent", StringComparison.OrdinalIgnoreCase))
{
var data = item.Data as JObject;
var eventData = data.ToObject<SubscriptionValidationEventData>();
var responseData = new SubscriptionValidationResponse
{
ValidationResponse = eventData.ValidationCode
};
return Ok(responseData);
}
else
{
await DoSomethingWithEvent(item.Data.ToString());
}
}
}
catch (Exception ex)
{
telemetry.TrackException(ex);
throw;
}
return Ok();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.