在 MVC 框架中使用基于角色的控制器是否可以接受
如果我的站点有多个用户角色,例如管理员、用户、经理,并且有多个功能模块可能由一个特定用户或所有用户使用,我应该如何命名我的控制器?
是否可以使用基于角色的控制器(例如管理员、用户和经理控制器)以及用于共享功能的控制器(例如产品控制器)?
对于仅由一个用户角色使用的一小部分功能,我可以将其保留在基于用户的控制器内,例如,具有产品类别的所有添加/删除/更新功能,我可以将其保留在管理控制器内还是应该拥有自己的功能控制器,即使它只有几行代码?
当在网上搜索这样做的约定时,我只提供了命名实际文件的方法,而其他来源仅解释了控制器的功能,而不解释什么应该是控制器,什么不应该是控制器。
如果这是主观的,我也很乐意将其作为答案,但就目前情况而言,我不确定什么是可以接受的,以及基于角色的控制器在 MVC 框架中是否可以接受。
If my site has several user roles say Admin, User, Manager and there are several modules of functionality that may be used by one particular user or by all users how should I go about naming my controllers?
Is it OK to have role based controllers such as an Admin, User and Manager controller as well as controllers for shared functionality such as Products controller?
And for small parts of functionality that is used by only one user role can I keep that inside the user based controller e.g. having all the add/remove/update functionality for product categories can I have that inside the Admin controller or should it have its own controller even though it will only be a few lines of code?
When searching the net for conventions on doing this I am only provided with ways to name the actual file and other sources only explain the controller functionality and not what should and should not be a controller.
If this is subjective I am also happy to take that as an answer, but as it currently stands I am unsure of what is acceptable and whether or not role based controllers are acceptable in the MVC framework.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就我个人而言,我已将 ASP.NET MVC 项目升级到版本 2-beta 版本 2,并将管理相关内容移至不同区域。
通过这种方式,您可以使控制器名称与其功能相关,但从专用区域运行它们。
Personally, I have upgraded my ASP.NET MVC project to version 2-beta release 2 and moved admin related stuff to different area.
This way you can keep your controller names related to their function but run them from dedicated area.