将不同的 asp.net mvc AREA 中的公共/管理区域分开会导致双控制器吗?
我的网站有多个公共页面,显示一些列表,如新闻、产品等......每个人都可以看到。所以我有一个 NewsController 和 ProductController。创建/编辑操作只能/必须由管理员执行。当我将管理内容(创建/编辑)与公共内容(列表)分开时,我将创建 2 个公共/管理区域,每个区域都有自己的控制器。这意味着我将有两个 ProductController,一个具有列表操作,一个具有创建/编辑操作,以及两个 NewsController 相同的游戏...
这有意义吗?我看起来很干——不要重复自己!
您将如何处理有关新的 asp.net AREA 功能的场景?
My site has multiple public pages showing some lists like news,products etc... everyone can see. So I have a NewsController and ProductController. The Create/Edit action can only be/must only be executed by the admin. When I separate the admin stuff (Create/Edit) from the public stuff(List) I would create 2 areas public/admin each having its own controller. That means I would have TWO ProductController one with List action and one with Create/Edit action and TWO NewsController same game...
Would that make sense? I looks like DRY - don`t repeat yourself!
How would you handle that scenario concerning the new asp.net AREA feature?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道你是如何重复自己的话?我总是为增删改查操作创建一个管理区域。您应该将控制器之外的所有逻辑移至一个单独的类中,并且根据该站点的大小,可能完全是一个单独的项目。看看 Raccoon 博客如何构建他们的项目。通过研究他们的代码,我学到了很多东西。如果您对如何构建代码有疑问,我建议您查看 - https://github.com/ayende/RaccoonBlog/tree/master/RaccoonBlog.Web。我相信他们有一个很好的例子来说明如何正确实施管理区域。
I'm not sure how you are repeating yourself? I always create an admin area for crud operations. You should be moving all of your logic outside of your controllers into a separate class, and depending on how big this site, maybe a separate project altogether. Take a look how the Raccoon Blog structures their project. I have learnt a great deal from studying their code. If you are having questions on how to structure your code, I suggest looking over there to - https://github.com/ayende/RaccoonBlog/tree/master/RaccoonBlog.Web. I believe they have an excellent example of how to implement admin areas correctly.
AuthorizeAttribute 是我处理它的方式,我不会使用区域来划分权限。
AuthorizeAttribute is how I'd handle it, I wouldn't use Areas to partition permissions.