Azure API 管理 - 操作的 Etag

发布于 2025-01-18 16:42:09 字数 146 浏览 3 评论 0 原文

我们是Azure API管理的新手。我们正在缓存DataVerse Master实体Web API调用,并希望查看如何添加ETAG作为Azure API管理中响应标头的一部分(后端呼叫也没有此标头)。我们如何在操作级别检索它?并且是否有任何参考文献文档。抱歉找不到任何。提前致谢

We are new to Azure API management. We are caching Dataverse master entities web api calls and looking to see how we can add ETag as part of response headers in Azure API Management(Backend call doesnt have this header as well). How do we retrieve this at Operations level ? and is there any reference documentation available. Sorry could not find any. Thanks in Advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〃温暖了心ぐ 2025-01-25 16:42:09

我们正在缓存DataVerse Master实体Web API调用,并希望查看如何将ETAG作为Azure API管理中的响应标头的一部分添加(后端呼叫也没有此标头)。我们如何在操作级别检索它?

  1. 获取由标识符指定的后端的实体状态(ETAG)版本。
HEAD https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendId}?api-version=2021-04-01-preview
  1. web api api实现
public class OrdersController : ApiController
{
    ...
    public IHttpActionResult FindOrderByID(int id)
    {
        // Find the matching order
        Order order = ...;
        ...

        var hashedOrder = order.GetHashCode();
        string hashedOrderEtag = $"\"{hashedOrder}\"";
        var eTag = new EntityTagHeaderValue(hashedOrderEtag);

        // Return a response message containing the order and the cache control header
        OkResultWithCaching<Order> response = new OkResultWithCaching<Order>(order, this)
        {
            ...,
            ETag = eTag
        };
        return response;
    }
    ...
}

您可以参考什么是etag,以及为什么人们使用它

We are caching Dataverse master entities web api calls and looking to see how we can add ETag as part of response headers in Azure API Management(Backend call doesnt have this header as well). How do we retrieve this at Operations level ?

  1. Get the entity state (Etag) version of the backend specified by its identifier.
HEAD https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendId}?api-version=2021-04-01-preview
  1. Web API implementation:
public class OrdersController : ApiController
{
    ...
    public IHttpActionResult FindOrderByID(int id)
    {
        // Find the matching order
        Order order = ...;
        ...

        var hashedOrder = order.GetHashCode();
        string hashedOrderEtag = 
quot;\"{hashedOrder}\"";
        var eTag = new EntityTagHeaderValue(hashedOrderEtag);

        // Return a response message containing the order and the cache control header
        OkResultWithCaching<Order> response = new OkResultWithCaching<Order>(order, this)
        {
            ...,
            ETag = eTag
        };
        return response;
    }
    ...
}

You can refer to Backend - Get Entity Tag, Does Azure Search Provides Etags for managing concurrency for Add, Update or Delete Documents? and What is ETag and why people use it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文