行级安全性
如何防止用户只更新数据库中的行。
例如: 用户负责一所学校。他们可以更改该学校的领域,但仅限于该学校。
因此: SchoolId、OwnerID、Name、PhoneNumber
我实现了一个函数: CanEditSchool(SchoolID) 如果用户不是特定学校的所有者,则会引发异常。
有更好的解决方案吗?我使用 linq2sql 作为 orm。
How do you prevent a user to only update their row in the database.
For example:
A user is responsible for a school. They can change fields for that school, but only that school.
Thus: SchoolId, OwnerID, Name, PhoneNumber
I've implemented a function that:
CanEditSchool(SchoolID) If the user isn't the owner of the specific school it throws an exception.
Is there a better solution? I'm using linq2sql as the orm.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据您处理数据上下文的方式,您可以在数据上下文上使用 LoadOptions。
http://msdn.microsoft.com/en-我们/库/Bb386915(v=VS.90).aspx
Depending on how you handle your datacontext, you can use LoadOptions on the datacontext.
http://msdn.microsoft.com/en-us/library/Bb386915(v=VS.90).aspx
一种似乎不是最佳的解决方案是为用户创建一个视图,仅包含其管辖范围内的学校:
One solution, which doesn't seem optimal, would be to create a view for the user, containing only the school under their jurisdiction:
您的控制器操作应该检查您的安全功能,以确保登录用户能够编辑有问题的项目。如果没有,您应该将它们发送到“权限被拒绝”类型的页面/视图。
不过,您的
CanEditSchool
函数不需要引发异常。它的名字表明它将返回一个bool
;如果他们可以编辑,则为true
;如果不能编辑,则为false
。Your controller action should check your security function to assure that the logged-in user is able to edit the item in question. If not, you should send them to a 'permission denied' type of page/view.
Your
CanEditSchool
function does not need to throw an exception, though. It's name suggests that it would return abool
;true
if they can edit it,false
if not.