ASP.NET路由在API管理服务后面

huangapple go评论77阅读模式
英文:

ASP.NET routing behind an API management service

问题

Here are the translated parts:

尽管这并不是世界上最好的事情,但我有一个设置,其中我列出了一些 Web 应用程序作为 Azure API 管理服务中的 API。

我注意到像 Html.ActionLink 这样的调用会生成一个基于 Web 应用程序 URL 的 URL,而不是 APIM 实际使用的 实际 URL。

例如,如果我有一个名为 "example-web-app" 的 Web 应用程序,Html.ActionLink 生成的 URL 可能是

https://example-web-app/Home/Index

但如果我通过 APIM 调用它,我的起始 URL 将是

https://somedomain.com/examplewebapp

是否有一种方法可以强制像 Html.ActionLink 这样的调用生成自定义 URL?或者这是否需要成为整个 Web 应用程序的通用设置?

编辑:原来是缓存问题。然而,设置 API URL 后缀会导致以下情况:

URL:

https://somedomain.com/examplewebapp/Home/Index

Html.ActionLink 生成的 URL:

https://somedomain.com/Home/Index

英文:

Whilst it's not the nicest thing in the world, I have a setup where I have a handful of web apps listed as APIs in an API Management Service in Azure.

I've noticed that a call like Html.ActionLink generates a URL based on the web app URL, rather than the actual URL being used by the APIM.

For example, if I have a web app called "example-web-app" the URL produced by Html.ActionLink might be

https://example-web-app/Home/Index

But if I'm calling it through APIM, my start URL will be

https://somedomain.com/examplewebapp

Is there a way to force calls like Html.ActionLink to produce a custom URL? Or would this need to be a generic setting for the entire web app?

Edit: Turns out there was a caching issue. However, setting the API URL suffix causes the following:

URL:

https://somedomain.com/examplewebapp/Home/Index

Html.ActionLink generated URL:

https://somedomain.com/Home/Index

答案1

得分: 0

redirect-content-urls策略是针对以下情况创建的:https://learn.microsoft.com/azure/api-management/redirect-content-urls-policy 它将尝试将您的API的后端URL在响应中替换为APIM的前端URL。如果对您的情况来说过于严格,还可以使用常规的find-and-replace-policy(https://learn.microsoft.com/en-us/azure/api-management/find-and-replace-policy)。

英文:

redirect-content-urls policy was created with this scenario in mind: https://learn.microsoft.com/azure/api-management/redirect-content-urls-policy It will try to replace your API's backend URLs in response with APIM's frontend URL. If it proves to be too rigid for your scenario, regular find-and-replace-policy (https://learn.microsoft.com/en-us/azure/api-management/find-and-replace-policy) could also be used.

huangapple
  • 本文由 发表于 2023年6月29日 05:47:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76576909.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定