Teach you to add permissions to the Process Control program

Source: Internet
Author: User
Tags reference connectionstrings

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.