![](/img/trans.png)
[英]When No Route Matches, getting list of all available routes; how to disable?
[英]How to disable getting only meta data in route OData
我添加了两条路线。 其中之一包含动态前缀:
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请求的元数据。 那么我该如何解决这个问题呢?
我在路由中添加了自定义约定并忽略了显示如下元数据:
conventionsWithContextTokenPrefix.Except(conventionsWithContextTokenPrefix.OfType<MetadataRoutingConvention>())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.