如何管理 ASP.NET MVC2 中用户类型之间的显着功能差异

发布于 2024-09-14 11:24:35 字数 361 浏览 7 评论 0原文

我想我可能把我的控制器弄乱了。我有一个相当简单的网站,允许“员工”或“客户”类型的用户查看项目。工作人员可以访问所有项目,可以添加和删除它们,添加和删除用户,为项目分配客户端权限等。

就目前情况而言,这意味着我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么这么可爱啊 2024-09-21 11:24:35

您是否考虑过像这样拆分控制器:

  • ClientUserController

  • ClientProjectController

  • StaffUserController

  • StaffProjectController

像这样拆分将允许您可以轻松地为每种用户类型提供专门的控制器和视图。在每个“Staff”控制器顶部使用单个身份验证属性来保护访问。

通过设置适当的路由,您可以为每种控制器类型维护友好的 URL:例如

  • /User/Edit(显示所有用户详细信息,
    但只允许编辑电子邮件字段)
  • 员工/用户/编辑(允许编辑所有
    用户字段)

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

  • /User/Edit (Shows all User detail,
    but only allows edit of Email field)
  • Staff/User/Edit (Allows edit of all
    User fields)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文