【问题标题】:How to disable getting only meta data in route OData如何禁用在路由 OData 中仅获取元数据
【发布时间】:2020-04-29 12:46:43
【问题描述】:

我添加了两条路线。其中之一包含动态前缀:

ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
        builder.EntityType<UOM>();
        var entityType = builder.EntityType<Product>();
        builder.EntitySet<Product>("Products");
        builder.EntitySet<UOM>("UOMs");

        var model = builder.GetEdmModel();
        config.MapODataServiceRoute(
        routeName: "ODataRoute",
        routePrefix: null,
        model: model);

        config.MapODataServiceRoute(
        routeName: "ODataRouteWithContext",
        routePrefix: "{context}/",
        model: model);

现在当我发送https://localhost:44326/ 时,我将获得元数据:

但是当我尝试像https://localhost:44326/xyz 这样的东西时,它也会返回元数据。

第二条路线的目的是从特定的上下文中获取实体。例如,https://localhost:44326/ac2db7f3-7581-4e6a-afa0-c4548d6ae89a/Products 因此,上下文前缀应该只是 Guid 类型。但我不想显示 https://localhost:44326/xyz 请求的元数据。那么我该如何解决这个问题呢?

【问题讨论】:

    标签: routes odata prefix


    【解决方案1】:

    我在路由中添加了自定义约定并忽略了显示这样的元数据:

    conventionsWithContextTokenPrefix.Except(conventionsWithContextTokenPrefix.OfType<MetadataRoutingConvention>())
    

    【讨论】:

      猜你喜欢
      • 2018-10-31
      • 1970-01-01
      • 2010-11-29
      • 2020-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多