You are developing an ASP.NET Core Web API that will serve as a webhook subscriber for an Azure Event Grid custom topic. To start receiving events, you must implement the synchronous validation handshake. You have created the following controller action method to handle incoming POST requests:
csharp
[HttpPost]
public async Task<IActionResult> HandleEvent()
{
using var reader = new StreamReader(Request.Body);
string requestBody = await reader.ReadToEndAsync();
EventGridEvent[] events = EventGridEvent.ParseMany(BinaryData.FromString(requestBody));
foreach (EventGridEvent ev in events)
{
if (ev.EventType == "Microsoft.EventGrid.SubscriptionValidationEvent")
{
var data = ev.Data.ToObjectFromJson<SubscriptionValidationEventData>();
// [MISSING CODE]
}
}
return new OkResult();
}
Which of the following code segments should you use to replace `// [MISSING CODE]` to successfully complete the synchronous subscription validation handshake?
- var responseData = new { validationResponse = data.ValidationCode };
return new OkObjectResult(responseData);Answer - Bvar responseData = new { validationCode = data.ValidationCode };
return new OkObjectResult(responseData); - Creturn new OkResult();
- DResponse.Headers.Add("Webhook-Allowed-Origin", "eventgrid.azure.net");
return new OkResult();