【问题标题】:how to secure add or delete entities with breezejs如何使用微风保护添加或删除实体
【发布时间】:2015-07-25 00:47:59
【问题描述】:

在向微风js添加或删除实体后如何保护 SaveChanges?

  var newTodo = todoType.createEntity(initialValues);
  manager.addEntity(newTodo);

我只想向已登录的用户添加/删除实体。其他用户不应该能够通过 javascript hack 向其他用户添加实体。

可以通过在服务器上编辑 EFContextProvider 来仅查询允许的实体。但它如何与删除或添加一起工作?

【问题讨论】:

    标签: javascript c# asp.net security breeze


    【解决方案1】:

    您可以使用防止在服务器端保存更改

    覆盖 contexProvider 的 BeforeSaveEntitiesDelegate 方法。

    例如

    _contextProvider.BeforeSaveEntitiesDelegate = BeforeSaveEntities;
    
    private Dictionary<Type, List<EntityInfo>> BeforeSaveEntities(Dictionary<Type, List<EntityInfo>> arg)
            {
                var resultToReturn = new Dictionary<Type, List<EntityInfo>>();
                foreach (var type in arg.Keys)
                {
                    var entityName = type.FullName;
                    var list = arg[type];
                    if (entityName == "xyz" && list[0].EntityState!="Added")
                    {
                        resultToReturn.Add(type, list);
                    }
                }
                return arg;
            }
    

    这不会保存新添加的实体名称“xyz”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多