Azure中配置Webhook传递属性后无法注册Event Grid订阅的问题求助
Hi Ashok, sorry to hear you're stuck on this issue—let's walk through some targeted fixes and checks to get your webhook subscription working with custom delivery properties:
Common Causes & Fixes
1. Ensure Your Validation Logic Handles Custom Headers
When you add delivery properties like Authorization or custom content-type headers, Event Grid includes these headers during the validation request (not just event delivery). If your REST service's validation code only expects the default validation payload without extra headers, it might reject the request.
- Double-check that your validation endpoint first processes any custom headers (e.g., validating an auth token in the
Authorizationheader) before handling the Event Grid validation logic (returning thevalidationCodefrom the request body). - Verify that your service accepts
OPTIONSrequests (if using the validation handshake method) with these custom headers enabled.
2. Validate Content-Type Compatibility
If you're overriding the content-type header:
- Make sure the value you specify is supported by Event Grid (e.g.,
application/jsonorapplication/cloudevents+json). Using an unsupported format will cause validation to fail. - Confirm your REST service can parse the request body in the specified content-type format during both validation and event delivery.
3. Check Web App Access Restrictions & Middleware
Azure Web App security layers might block requests with custom headers:
- Temporarily disable IP restrictions, WAF rules, or custom authentication middleware to test if they're intercepting the validation request.
- If you re-enable these restrictions, add the official Event Grid service IP ranges to your allowlist to ensure requests aren't blocked.
4. Dig Into Detailed Failure Logs
- In the Azure Portal, navigate to your Event Grid subscription and check the Delivery Failures tab for specific error codes (e.g.,
401 Unauthorized,400 Bad Request) and failure details—this will pinpoint whether the issue is with auth, request formatting, or something else. - Enable detailed logging for your Web App under App Service Logs, then inspect the incoming request headers and service response status codes to confirm if your custom delivery properties are being sent correctly.
5. Test with Azure CLI (Optional)
Use the Azure CLI to create the subscription with delivery properties, which often returns more verbose error messages than the Portal:
az eventgrid event-subscription create \ --name your-subscription-name \ --source-resource-id /subscriptions/{your-sub-id}/resourceGroups/{your-rg}/providers/{resource-provider}/{resource-name} \ --endpoint https://your-webapp.azurewebsites.net/api/your-event-endpoint \ --delivery-attribute-mapping "headerName=Authorization,headerValue=Bearer your-auth-token"
If you can share specific error codes or log snippets from your failed attempts, we can narrow this down further!
内容的提问来源于stack exchange,提问作者Ashok Peravali

