how to hide metadata in web api 2, odata

*爱你&永不变心* 提交于 2019-12-05 13:03:39

If want to hide metadata (/$metadata) or service document (/), can remove the the MetadataRoutingConvention from existing routing conventions, e.g.:

var defaultConventions = ODataRoutingConventions.CreateDefault();
var conventions = defaultConventions.Except(
    defaultConventions.OfType<MetadataRoutingConvention>());
var route = config.MapODataServiceRoute(
    "odata",
    "odata",
    model,
    pathHandler: new DefaultODataPathHandler(),
    routingConventions: conventions);

If only expose a few properties per type, can use ODataModelBuilder instead of ODataConventionModelBuilder. E.g., some example:

ODataModelBuilder builder = new ODataModelBuilder();
EntityTypeConfiguration<Customer> customer = builder.EntitySet<Customer>("Customers").EntityType;
customer.HasKey(c => c.Id);
customer.Property(c => c.Name);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!