简体   繁体   中英

How do I get .NET redirects to work with an API deployed to an Azure API Management Service with a URL suffix?

I have several APIs which are made available by an Azure API Management Service.

The API Management Service has a domain and each API has its own "API URL Suffix" setup in the Azure portal like below:

The problem is that when any of these APIs performs a redirect using the Redirect or RedirectToAction methods, it doesn't include the "API URL Suffix" in the new URL and this causes Azure to return a 404 error.

eg

A call to

https://www.example.com/first/api/v1/controller/action

that should redirect to

https://www.example.com/first/api/v1/controller/redirected

actually redirects to

https://www.example.com/api/v1/controller/redirected

which can't be found.

I don't know if this is an Azure problem, a coding problem, or an HTTP problem.

Do relative Location headers only take the domain into account when redirecting and nothing that follows the domain?

Should I just hard code the "API URL Suffix" in the Redirect and RedirectToAction calls?

Would I have to setup some sort of proxy for my development environment then to add the suffix before the actual routes when testing?

Would I have to manually make sure both the code and the Azure settings are in sync?

Or is there some sort of Azure setting that will fix this so I redirects will actually work with an "API URL Suffix"?

Or is there any other kind of workaround for this? Is there some ugly string manipulation I would have to do using the request URL?

You can use the policy in API Management:

Rewrite URL

<policies>
<inbound>
    <base />
    <rewrite-uri template="/v2/US/hardware/{storenumber}&{ordernumber}?City=city&State=state" />
</inbound>
<outbound>
    <base />
</outbound>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM