Imran Arshad
Imran Arshad

Reputation: 4012

Azure Application Gateway is Redirecting request to App Service

I have application gateway sitting in front of Azure App Service (Standard) . I have .Net Core 3.1 basic MVC web app hosted on App Service.

Problem

The problem is when I hit Application Gateway URL (default hostname) it redirects the request to Azure App Service URL which is not what I want. I want APP gateway to proxy the request but not actually redirect me to the Azure App Service.

Possible Cause:

I believe it's a known thing. Redirection is possibly being caused because of Location Header in response as mentioned here Redirection Issue in Documentation.

Steps taken:

I have tried to rewrite the URL as suggested here Rewrite Response in official documentation however when I rewrite the response header It not working. Some time I don't get the response and other times It gets into Redirection Loop. Please note I am not using custom domain as suggested in the document but default App Gateway host name (xx.australiaeast.cloudapp.azure.com)

I have tried following header values

{http_resp_Location_1}://{var_host}{http_resp_Location_2}

http://{var_host}{http_resp_Location_2}

Any help/guidance is highly appreciated.

Imran

Upvotes: 3

Views: 2063

Answers (1)

smita sukumaran
smita sukumaran

Reputation: 21

If you are using AGW v2, then here is the solution.

You can create a rewrite rule condition with specific app service backend as follows:

    {
        "ruleSequence": 101,
        "conditions": [
            {
                "variable": "http_resp_Location",
                "pattern": "(https?):\\/\\/test.abc.appserviceenvironment.net(.*)$",
                "ignoreCase": true,
                "negate": false
            }
        ],
        "name": "test-rewrite-rule",
        "actionSet": {
            "requestHeaderConfigurations": [],
            "responseHeaderConfigurations": [
                {
                    "headerName": "Location",
                    "headerValue": "{http_resp_Location_1}://contoso.com{http_resp_Location_2}"
                }
            ]
        }
    }

Upvotes: 2

Related Questions