如何管理 ASP.NET MVC2 中用户类型之间的显着功能差异
我想我可能把我的控制器弄乱了。我有一个相当简单的网站,允许“员工”或“客户”类型的用户查看项目。工作人员可以访问所有项目,可以添加和删除它们,添加和删除用户,为项目分配客户端权限等。
就目前情况而言,这意味着我有一个 UserController 和 ProjectController,其中散布着身份验证属性(即客户端可以更改他的电子邮件,但没有其他权限,客户无法添加/删除/编辑项目,但可以浏览其内容)。
而且,根据用户类型/角色,我切换菜单组件。我是否应该拆分我的控制器以缩小关注范围,或者这是区域的候选者?我“感觉”我的大部分代码正在检查用户 X 是否可以根据他的角色和显式的每个项目权限执行操作 Y。
附言。我多次重写了这个主题,试图让它变得更短:\
I think I may have made a mess of my controllers. I have a fairly simple site that allows users of type "Staff" or "Client" to view Projects. Staff have access to all projects, can add and delete them, add and delete users, assign clients permission to projects, etc.
As it stands this means I have a UserController and ProjectController, littered with Authentication attributes (ie. so a Client can change his email but nothing else like permissions, and Clients can't add/remove/edit projects but can browse their contents).
And also, based on the user type/role, I switch out menu components. Should I be splitting up my controllers to have narrower focus, or is this a candidate for Areas? I "feel" like to much of my code is checking whether user X can do action Y based on both his role AND explicit per-project permissions.
PS. I rewrote the subject several times trying to make it shorter :\
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过像这样拆分控制器:
ClientUserController
ClientProjectController
StaffUserController
StaffProjectController
像这样拆分将允许您可以轻松地为每种用户类型提供专门的控制器和视图。在每个“Staff”控制器顶部使用单个身份验证属性来保护访问。
通过设置适当的路由,您可以为每种控制器类型维护友好的 URL:例如
但只允许编辑电子邮件字段)
用户字段)
Have you considerd splitting your controllers like so:
ClientUserController
ClientProjectController
StaffUserController
StaffProjectController
Splitting like this would allow you to easily have specialised controllers and views for each user type. Use a single Authentication attribute at the top of each "Staff" controller to secure access.
By setting up approriate routes, you could mainatin friendly URLs to each controler type: eg
but only allows edit of Email field)
User fields)