当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net mvc - Where to handle Roles in an MVC Application (C#, WebApi)

问题描述:

I'm currently working on an application which allows users with multiple Roles to select one which is then used throughout the application to display content and perform actions for that particular role (It's not about authorisation which is handled separately). The current code base is littered with "if role == "x" else" statements and similar constructs in the Controller and Views.

Some code has now be moved into services which raises the question where should Roles be handled? I don't think Views should have knowledge of the Roles but I'm not so sure about Services.

The options are for ex. passing the selected role into a service or providing specialised service methods for each role separately and have the controller choose which one to use.

分享给朋友:
您可能感兴趣的文章:
随机阅读: