使用实体框架进行动态数据屏蔽 [英] Dynamic data masking with Entity framework

查看:120
本文介绍了使用实体框架进行动态数据屏蔽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在实体框架中使用SQL的动态数据屏蔽?

Is it possible to use SQL's Dynamic data masking with Entity framework?

如果有可能,是否有任何方法可以将其与Asp.Identity结合? 我正在从事的项目要求对某些用户角色屏蔽数据,并且对其他用户可见.

If it is possible, is there any way to combine it with Asp.Identity? Project I'm working on requires that data is masked for certain user roles and visible to others.

我们正在使用数据库优先方法和Entity框架,其中的数据字段用以下字符屏蔽:

We are using database first approach and Entity framework with data fields masked with:

MASKED WITH (FUNCTION = 'default()')

,对于管理员来说必须可见,而对其他用户角色则应保持屏蔽.用户角色是通过Asp.identity定义的.

that need to be visible to admins and remain masked to other user roles. User roles are defined thru Asp.identity.

推荐答案

如果非常适合您的应用程序体系结构,则可以尝试通过此博客文章

If it suits well your app architecture you can try approach from this blog post this blog post.

您可以用两个词创建特殊的db用户,该用户将代表您的其他用户角色".然后创建两个DbContext实例:一个实例用于admin,另一个实例用于您的其余角色.因此,基本上,所有这些都与连接字符串中提供的用户身份有关.

In two words you can create special db user which will represent your "other user roles". And then create two instances of DbContext: one for admin and one for the rest of your roles. So, basically, it's all about user identity provided in connection string.

例如,可以根据当前用户使用正确的连接字符串来正确设置DbContext实例,例如,可以提供依赖项注入.

Correct instance of DbContext with right connection string based on current user you can, for example, provide with dependency injection.

这篇关于使用实体框架进行动态数据屏蔽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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