注册会员,创建你的web开发资料库,  wf提供权限控制的功能,其中包括两种方式:activedirectoryrole(通过活动目录用户)和webworkflowrole(asp.net role)。下面我以webworkflowrole的方式作为权限控制例子做介绍,首先需要安装aspnetdb数据库(通过运行微软提供的aspnet_regsql.exe文件);app.config文件配置如下:
<?xmlversion="1.0"encoding="utf-8" ?> 
<configuration> 
 <connectionstrings> 
    <addname="sqlserverconnection" 
         connectionstring="integrated security = 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>
 
  通过下面的代码产生角色:
        ///<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); 
            }             
        }
  假如用登录用户"betty"为部门经理角色,通过下面的代码可以把登录用户和权限控制相结合:genericidentity genidentity = new genericidentity("betty ");通过调用外部事件activity的方法把genidentity作为事件的参数传入流程中。
  在流程定义的文件中(workflow1.cs)定义公共变量:
public workflowrolecollection eainitiators = new system.workflow.activities.workflowrolecollection();
  通过下面的代码把部门经理角色增加到流程角色列表:
            //装载部门经理角色 
            webworkflowrole eainitiatorsrole = new webworkflowrole("deptmanager"); 
        eainitiators.add(eainitiatorsrole);
 
  wf通过检查传入的登录名参数是否存在于流程角色列表的某个角色中来实现流程权限控制。