Skip to content

Instantly share code, notes, and snippets.

@JeremyLikness
Created February 1, 2019 18:59
Show Gist options
  • Save JeremyLikness/4b0218cf984c7ea5bfbb1e78bb654421 to your computer and use it in GitHub Desktop.
Save JeremyLikness/4b0218cf984c7ea5bfbb1e78bb654421 to your computer and use it in GitHub Desktop.
Receiving an event grid event
[HttpPost]
public IActionResult Post([FromBody]EventGridEvent[] value)
{
if (value == null || value.Length != 1 || value[0].Data == null)
{
_logger.LogError("Bad event.");
return BadRequest();
}
_logger.LogInformation($"Received event with type {value[0].EventType}");
if (value[0].EventType == "Microsoft.EventGrid.SubscriptionValidationEvent")
{
var subscriptionValidation = value[0].Data.ToObject<SubscriptionValidationEvent>();
_logger.LogInformation($"Validating subscription with token {subscriptionValidation.ValidationCode}");
return Ok(new SubscriptionValidationResponse
{
ValidationResponse = subscriptionValidation.ValidationCode
});
}
_logger.LogInformation($"Parsing payload {value[0].Data}...");
var msg = value[0].Data["message"].ToString();
_logger.LogInformation($"Received message: {msg}");
return Ok();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment