How do I customize a unique response schema for 4xx and 5xx?

Ni, Yibo 20 Reputation points
2024-01-18T09:15:42.7766667+00:00

I'm working on the Application Gateway and tried Custom error pages for response customized. My purpose is to return a same json schema for different codes(4xx/5xx) which may due to WAF rules blocked request so I write a json data into the *.html.

User's image

{
  "error": {
    "code": "403",
    "message": "Azure Application Gateway Forbidden"
  }
}
  1. Is there a better way matching my requirement to hande all responses?
  2. We usually get a response through an interface call rather than a browser. Can I set customer parameters to response header or body?
Azure Application Gateway
Azure Application Gateway
An Azure service that provides a platform-managed, scalable, and highly available application delivery controller as a service.
982 questions
Azure Web Application Firewall
{count} votes

Accepted answer
  1. GitaraniSharma-MSFT 48,196 Reputation points Microsoft Employee
    2024-01-18T13:11:06.4833333+00:00

    Hello @Ni, Yibo ,

    Welcome to Microsoft Q&A Platform. Thank you for reaching out & hope you are doing well.

    I understand that you would like to know if you can customize a unique response schema for 4xx and 5xx errors on your Application gateway.

    Is there a better way matching my requirement to handle all responses?

    As of today, the only way to create a custom error page in Application gateway is to ensure the error page should be in *.htm or *.html extension type. You need to provide the URL for the error page for the configuration. There is no other way to handle the responses.

    Refer: https://learn.microsoft.com/en-us/azure/application-gateway/custom-error?source=recommendations#requirements

    https://learn.microsoft.com/en-us/rest/api/application-gateway/application-gateways/create-or-update?view=rest-application-gateway-2023-06-01&tabs=HTTP#applicationgatewaycustomerror

    We usually get a response through an interface call rather than a browser. Can I set customer parameters to response header or body?

    After you specify an error page in your application gateway's configuration, your gateway verifies the connectivity to the HTML page over the internet. It then downloads the file on its local cache. When a client faces an error, your application gateway returns a response code and that HTML page. Any externally referenced resources (such as images, JavaScript, and CSS files) are fetched directly by the client.

    This is not possible through an interface call.

    Also, HTTP headers and URL Rewrites aren't supported when the application gateway is configured to redirect the requests or to show a custom error page.

    Refer: https://learn.microsoft.com/en-us/azure/application-gateway/rewrite-http-headers-url#limitations

    So, when you have a custom error page configured in your Application gateway, you cannot configure header rewrites. This is a limitation.

    If you wish you may also leave your feedback in the below forum requesting this feature. All the feedback you share in these forums will be monitored and reviewed by the Microsoft engineering teams responsible for building Azure.

    https://feedback.azure.com/d365community/forum/8ae9bf04-8326-ec11-b6e6-000d3a4f0789

    Kindly let us know if the above helps or you need further assistance on this issue.


    Please don’t forget to "Accept the answer" wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

0 additional answers

Sort by: Most helpful