Role-Based Content asp.net mvc

后端 未结 4 504
-上瘾入骨i
-上瘾入骨i 2020-12-29 00:21

I wish to display content depending on the given role(s) of the active user , in the ASP.NET MVC.

Compare the old fashion way, using WebForms:

protec         


        
4条回答
  •  执笔经年
    2020-12-29 00:49

    The separation of concerns approach suggested in ASP.NET MVC 4 How do you serve different HTML based on Role? in my opinion is a better way to go.

    Personally I avoid IsInRole check as much as possible in the code and leave it to declarative means to achieve role based restriction as much as possible. This ensures code remains maintainable over time. I am not sure if this is a right or the wrong approach, but has worked well for me.

提交回复
热议问题