WF provides access control features, including two ways: Activedirectoryrole (through Active Directory Users) and webworkflowrole (asp.net role). Below I take the webworkflowrole way as the privilege control example to do the introduction, first needs to install the ASPNETDB database (by running Microsoft provided aspnet_regsql.exe file); The app.config files are configured as follows:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<addname="SqlServerConnection"
connectionString="IntegratedSecurity=SSPI;server=localhost\SQLExpress;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>
The
generates roles through the following code:
The following is a reference fragment:
///<summary>
///generation role
///</summary>
private void Cre Ateroles ()
{
if (! System.Web.Security.Roles.RoleExists ("Personnel"))
{
System.Web.Security.Roles.CreateRol E ("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.CreateR OLE ("Deptmanager");
String[] users1 = {"Betty", "Chris", "Anil", "Derek"};
String[] Deptmanagerrole = {"Deptmanager"};
System.Web.Security.Roles.AddUsersToRoles (users1, deptmanagerrole);
}
}
If you use the login user "Betty" for the department manager role, through the following code can be the login user and the rights control combination: genericidentity genidentity = new GenericIdentity ("Betty"); Genidentity is passed into the process as a parameter of the event by invoking the external event activity.
Define public variables in the file (Workflow1.cs) of the process definition:
The following is a reference fragment:
Public workflowrolecollection eainitiators = new System.Workflow.Activities.WorkflowRoleCollection ();
Add the Department Manager role to the process role list through the following code:
The following is a reference fragment:
Load Department Manager role
Webworkflowrole eainitiatorsrole = new Webworkflowrole ("Deptmanager");
Eainitiators.add (Eainitiatorsrole);
WF implements process permission control by checking whether the incoming login parameter exists in a role in the process role list.