breeze - breeze.js 中的服务器端验证和安全性

标签 breeze unit-of-work

我正在尝试使用 breeze.js 保存一些实体。 Breeze 工作正常,它会根据需要保存所有更改。但是,我无法验证并确保授权是服务器端的。从我目前收集到的信息来看,我猜想做到这一点的唯一方法是检查传递到保存包中的 JObject 并在服务器端构建相应的对象。我必须这样做(而不是依赖 Breeze.SaveChanges,因为我在服务器端有一些逻辑)。我该怎么做呢?以及如何构建 Breeze.WebApi。保存结果? 也欢迎提出解决此问题的任何其他方法

最佳答案

这应该通过实现自定义 EFContextProvider 来完成。

下面的代码为 Northwind 数据库实现了自定义 EFContextProvider,直接取自 documentation on the breeze.com website .

    public class NorthwindContextProvider: EFContextProvider<NorthwindIBContext>  {
    public NorthwindContextProvider() : base() { }

    protected override bool BeforeSaveEntity(EntityInfo entityInfo) {
      // return false if we don’t want the entity saved.
      // prohibit any additions of entities of type 'Role'
      if (entityInfo.Entity.GetType() == typeof(Role)
        && entityInfo.EntityState == EntityState.Added) {
        return false;
      } else {
        return true;
      }
   }

    protected override Dictionary<Type, List<EntityInfo>> BeforeSaveEntities(Dictionary<Type, List<EntityInfo>> saveMap) {
      // return a map of those entities we want saved.
      return saveMap;
    }
  }

关于breeze - breeze.js 中的服务器端验证和安全性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16893169/

相关文章:

matrix - scala breeze 将矩阵乘以转置

asp.net - Entity Framework asp.net 应用程序中的 UOW 和存储库

entity-framework-4 - EF4 - 存储库和工作单元

Breeze : how to access enum metadata

javascript - AngularJS 中的急切加载 Expand() 函数

javascript - 离线加载 Breeze 导航属性

nhibernate - 工作单元问题 - Nhibernate(隔离级别以及 UoW 中还有什么)

c# - 洋葱架构、工作单元和通用存储库模式

c# - 如何通过工作单元访问上下文中的方法?

javascript - TypeScript 与 BreezeJS 结合