以下是引用片段:
<?
xmlversion="1.0"encoding="utf-8" ?>
<configuration>
<connectionStrings>
<addname="SqlServerConnection"
connectionString="Integrated Security = SSPI;server=localhost/SQLEX
PRess;database=aspnetdb" />
</connectionStrings>
<system.web>
<roleManagerenabled="true"defaultProvider="SqlProvider">
<providers>
<addname="SqlProvider"connectionStringName="SqlServerConnection"
applicationName="ConsoleAppSample"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>
</system.web>
</configuration>
以下是引用片段:
///<summary>
///产生角色
///</summary>
private void CreateRoles()
{
if (!System.Web.Security.Roles.RoleExists("Personnel"))
{
System.Web.Security.Roles.CreateRole("Personnel");
string[] users = { "Amanda", "Jones", "Simpson", "Peter" };
string[] PersonnelRole = { "Personnel" };
System.Web.Security.Roles.AddUsersToRoles(users, PersonnelRole);
}
if (!System.Web.Security.Roles.RoleExists("DeptManager"))
{
System.Web.Security.Roles.CreateRole("DeptManager");
string[] users1 = { "Betty", "Chris", "Anil", "Derek" };
string[] DeptManagerRole = { "DeptManager" };
System.Web.Security.Roles.AddUsersToRoles(users1, DeptManagerRole);
}
}