asp.net成员身份-如何以编程方式确定用户是否在角色中

问题描述:

确定用户是否在角色中的代码是什么?

What is the code for determining if a user is in a role?

我已经通过"ASP.NET配置安全性"选项卡设置了所有用户,但现在希望在一些关键区域周围添加逻辑,以便只有具有特定角色的人员才能看到和访问这些区域.

I have set up all the users through the ASP.NET Configuration Security tab but now want to put logic around some key areas so only people in certain roles can see and access these areas.

if (User.IsInRole("rolename")) {
  // my action
}