Dynamic data masking with Entity framework

天涯浪子 提交于 2019-12-23 17:20:36

问题


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

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.

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

MASKED WITH (FUNCTION = 'default()')

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


回答1:


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

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.

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



来源:https://stackoverflow.com/questions/52078018/dynamic-data-masking-with-entity-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!