当前位置:首页 >> 编程开发 >> Visual C++ >> 内容

教你给流程增加权限控制程序

时间:2007/10/8 作者:平凡之路 来源:xuhantao.com 浏览:

WF提供权限控制的功能,其中包括两种方式:ActiveDirectoryRole(通过活动目录用户)和WebWorkflowRole(ASP.NET Role)。下面我以WebWorkflowRole的方式作为权限控制例子做介绍,首先需要安装aspnetdb数据库(通过运行微软提供的aspnet_regsql.exe文件);App.config文件配置如下:

<?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>

通过下面的代码产生角色:

以下是引用片段:
///<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通过检查传入的登录名参数是否存在于流程角色列表的某个角色中来实现流程权限控制。

相关文章
  • 没有相关文章
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 徐汉涛(www.xuhantao.com) © 2024 版权所有 All Rights Reserved.
  • 部分内容来自网络,如有侵权请联系站长尽快处理 站长QQ:965898558(广告及站内业务受理) 网站备案号:蒙ICP备15000590号-1