如何在 Asp.net 网络表单中使用 AddUsersToRoles 方法

How to use AddUsersToRoles Method in Asp.net web forms

我想为不同的用户添加特殊的特权。

所以我只想在我的 .cs 代码中使用 AddUsersToRoles 方法。

我在 html 代码中将超级用户、管理员、经理和员工作为下拉列表。

使用 AddUsersToRoles 方法购买如何在我的 .cs 文件中调用下拉列表?

我正在尝试编写这段代码,但在 ddroles(dropdown id) 附近出现错误。它不接受我使用的过载。

  Roles.AddUsersToRoles(username,ddroles);

你能帮我看看这个方法的使用方法和重载的写法吗

提前致谢。

Roles.AddUsersToRoles 的两个参数都需要字符串数组。

您需要提供如下内容 -

string[] usernames = {"johndoe", "janetdoe"};
string[] roleNames = {"Administrators", "Customers"};
Roles.AddUsersToRoles(usernames, roleNames);