1 /*******************************************************************************
2 // Copyright (C) 2000-2001 Microsoft Corporation. All rights reserved.
5 // Workflow Web Hosting Module.
8 // Implementation of Workflow Web Host Module.
11 // Date Ver By Remarks
12 // ~~~~~~~~~~ ~~~ ~~~~~~~~ ~~~~~~~~~~~~~~
13 // 02/22/05 1.0 [....] Implementation.
14 * ****************************************************************************/
16 #region Using directives
19 using System.Collections;
20 using System.Collections.Generic;
22 using System.Diagnostics;
24 using System.Collections.Specialized;
25 using System.Threading;
29 namespace System.Workflow.Runtime.Hosting
32 /// Cookie based rotuing module implementation
34 [Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
35 public sealed class WorkflowWebHostingModule : IHttpModule
37 HttpApplication currentApplication;
39 public WorkflowWebHostingModule()
41 WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "Workflow Web Hosting Module Created");
45 /// IHttpModule.Init()
47 /// <param name="application"></param>
48 void IHttpModule.Init(HttpApplication application)
50 WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "Workflow Web Hosting Module Initialized");
52 this.currentApplication = application;
54 //Listen for Acquire and ReleaseRequestState event
55 application.ReleaseRequestState += this.OnReleaseRequestState;
56 application.AcquireRequestState += this.OnAcquireRequestState;
59 void IHttpModule.Dispose()
64 void OnAcquireRequestState(Object sender, EventArgs e)
66 //Performs Cookie based routing.
67 WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "WebHost Module Routing Begin");
69 HttpCookie routingCookie = HttpContext.Current.Request.Cookies.Get("WF_WorkflowInstanceId");
71 if (routingCookie != null)
73 HttpContext.Current.Items.Add("__WorkflowInstanceId__", new Guid(routingCookie.Value));
75 //else no routing information found, it could be activation request or non workflow based request.
78 void OnReleaseRequestState(Object sender, EventArgs e)
80 //Saves cookie back to client.
81 HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("WF_WorkflowInstanceId");
85 cookie = new HttpCookie("WF_WorkflowInstanceId");
86 Object workflowInstanceId = HttpContext.Current.Items["__WorkflowInstanceId__"];
88 if (workflowInstanceId != null)
90 cookie.Value = workflowInstanceId.ToString();
91 HttpContext.Current.Response.Cookies.Add(cookie);