Developing Sequential Workflow In ASP.Net Applications
In this article i am going to explain how to create sequential workflow in asp.net.
step:1 ->;; Create New Sequential Workflow Project
Open Visual Studio 2008 –>; create a new project–>; Choose Sequential Workflow Library
at this point,the workflow project contains single workflow class(workflow1).
step:2 ->; Drag a IfElse activity onto the design surface from the toolbox.The designer looks like below figure below.
Note that while dragging activity on the surface you will see green (+ sign) which indicates a place where you can drop activity.(you can also refer figure below).
step:3 -> Drop Code activity inside ifElseBranchActivity1 and ifElseBranchActivity2 and name them as Authorized and UnAuthorized respectively.
step:4 -> set the Condition on ifElseBranchActivity1 to code condition and set the condition property to IsAuthorized.
private void IsAuthorized(object sender, ConditionalEventArgs e)
{
if (UserName == "sunil" && Password == "demo@123")
{
this.Result = "Welcome.aspx";
}
else
{
this.Result = "NotAuthorized.aspx";
}
}
Also create following to accept parameter value..
public string UserName { get; set; }
public string Password { get; set; }
public string Result { get; set; }
step:5 ->; Create asp.net application in the solution, add to more page Welcome.aspx and UnAuthorized.aspx i the application as shown below
Write down the following code on Login_Click.
protected void Login_Click(object sender, EventArgs e)
{
WorkflowRuntime wr = new WorkflowRuntime();
wr.AddService(new ManualWorkflowSchedulerService());
Dictionary parameters = new Dictionary();
parameters.Add("Result", "");
parameters.Add("UserName", txtUserName.Text);
parameters.Add("Password", txtPassword.Text);
wr.WorkflowCompleted += new EventHandler(wfRuntime_WorkflowCompleted);
WorkflowInstance wi = wr.CreateWorkflow(typeof(SequentialWorkflowDemo.Workflow1), parameters);
wi.Start();
ManualWorkflowSchedulerService ss = wr.GetService();
ss.RunWorkflow(wi.InstanceId);
}
also following line of code to redirect user to specific page.
void wfRuntime_WorkflowCompleted(object sender, WorkflowCompletedEventArgs e)
{
HttpContext.Current.Response.Redirect((string)e.OutputParameters["Result"]);
}
Your workflow application is ready to execute.Run your asp.net application.





Recent Comments