不要让扩展了在微风特定EntityTypes [英] Do not allow Expands for specific EntityTypes in Breeze

查看:145
本文介绍了不要让扩展了在微风特定EntityTypes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种优雅的方式,不允许具体EntityTypes是的在BreezeJS扩大。我们有我们露出了(有点)公共Web服务,并且有一些表,我们不希望成为一些消费者的服务是可见的。虽然我们只能公开Web API的方法对那些特定的表,服务的消费者仍然可以通过相关的表扩大访问这些表。

I'm searching for an elegant way to not allow specific EntityTypes to be expanded in BreezeJS. We have a (somewhat) public Web Service that we are exposing, and there are some tables that we don't want to be visible to some consumers of that service. Although we can only expose Web API Methods for those specific tables, consumers of the service could still access those tables by expanding from related tables.

注意:我已经张贴了这个问题的答案,给人一种变通。不过,我有兴趣,如果有任何人知道剥皮这个特殊的猫一个更优雅的方式。

Note: I've posted an answer to this question, giving a work-around. However, I'm interested if anyone out there knows a more elegant way of skinning this particular cat.

推荐答案

请求该功能被正式加入到微风 UserVoice的页面,沃德贝尔提出一个体面的解决方法:

On the UserVoice page for requesting this feature to be formally added to Breeze, Ward Bell suggests a decent work-around:

同时,在你的控制器,可以从检查为$ presence请求的查询字符串选择和$扩展,如果你看到它抛出一个异常。

Meanwhile, in your controller you can examine the query string from the request for presence of $select and $expand and throw an exception if you see it.

我猜这将是这个样子:

    [HttpGet]
    public IQueryable<Widget> Widgets() {
        if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["$expand"]))
        {
            throw new Exception("Ah ah ah, you didn't say the magic word!");
        }
        return _contextProvider.Context.Widgets;
    }

...以阻止所有的扩展,或者更具体的阻止展开特点,本身的东西。这是不是太寒酸了,但不是很优雅。

...to block all Expands, or something more specific to block the Expand of Features, itself. This isn't too shabby but not quite "elegant".

(是的,这是一个侏罗纪公园参考。)

这篇关于不要让扩展了在微风特定EntityTypes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆