限制对“功能模块”的访问在 ASP.NET MVC 中
我正在 ASP.NET 4 和 MVC2 中构建一个网站,该网站将具有高级功能,例如仅对付费订阅者可用的 SMS 通知。我还有用于库存和交易等的附加模块,
我已经在利用标准 MembershipProvider,并且倾向于使用角色来提供此功能。 即:拥有一个“SMSModule”角色,如果用户为附加短信服务付费,则用户将获得该角色
这使得控制器通过一些属性修饰变得简单,但我看到的问题是,将会有一堆条件代码分散在我的观点等中
是否有更好的方法在.NET 4和MVC2中提供“模块”风格的方法???
I am building a site in ASP.NET 4 and MVC2 that will have premium features, such as SMS notifications that will only be available to paid subscribers. I also have additional modules for things like Inventory, and Transactions etc
I am already leveraging the standard MembershipProvider, and am leaning towards using Roles tp provide this functionality.
ie: have an "SMSModule" role that the user gets if they pay for the add-on SMS service
This makes the controllers simple with a little attribute decoration, but the problem I see with this is that there will be a bunch of conditional code scattered through my views etc
Is there a better method of providing a "module" style approach in .NET 4 and MVC2???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将条件逻辑添加到视图模型中,使用控制器适当地设置视图模型,这应该没问题......有时您必须在视图中包含 if 语句,即使不是那么巧妙。当然,除非您使用像 Spark 这样的视图引擎,否则您的 if 语句被放置在另一个不显眼的位置,但它们仍然存在!您始终可以创建 HtmlHelpers 并将代码设置到服务器端并根据逻辑适当显示...
You can add your conditional logic to view models, use the controllers to set the viewmodels appropriately and it should be fine... Sometimes you have to have the if statements inside the views even if not so ellegent. Unless of course you are using a view engine like spark then your if statements are placed in another unobtrusive location, but they still exist! You can always create HtmlHelpers and set the code to the serverside and based on the logic display appropriately...
FWIW 我最终在 Spark View Engine 中使用了描述符的组合,以及自定义功能提供程序和关联的 ActionFilter
FWIW I ended up using a combination of Descriptors in Spark View Engine, along with a custom Feature provider and associated ActionFilter