/// <summary>
        /// Registers for notification for when the specified method is received in a HttpRequest
        /// </summary>
        /// <param name="method">The method notification will be registered for</param>
        /// <param name="onRequest">The callback to be notified when/if the method is received</param>
        public void RegisterForRequestMethodNotification(string method, HttpRequestCancelEventHandler onRequest)
        {
            // we must have a valid method
            HttpUtils.ValidateToken(@"method", method);

            // and we must have a valid callback
            if (onRequest == null)
            {
                throw new ArgumentNullException("onRequest");
            }

            // look up the list of handlers for the specified hook point, and then look up the method in that list to
            Hashtable requestHandlers = this[HttpRequestHookPoints.BeforeHttpRuntimeProcessing];

            // receive the list of handlers that is handling callback notification for methods in that list
            HttpRequestCancelEventHandler handlers = requestHandlers[method] as HttpRequestCancelEventHandler;

            // if the handler list is null
            if (handlers == null)
            {
                // add the handlers into the list by the method we're registering for
                requestHandlers.Add(method, handlers);
            }

            // now combine the callback with all of the existing handlers
            handlers = (HttpRequestCancelEventHandler)Delegate.Combine(handlers, onRequest);

            // and finally store that list of callbacks using the method as the key in the list from which we retrieved this initially
            requestHandlers[method] = handlers;
        }
		/// <summary>
		/// Registers for notification for when the specified method is received in a HttpRequest
		/// </summary>
		/// <param name="method">The method notification will be registered for</param>
		/// <param name="onRequest">The callback to be notified when/if the method is received</param>
		public void RegisterForRequestMethodNotification(string method, HttpRequestCancelEventHandler onRequest)
		{
			// we must have a valid method
			HttpUtils.ValidateToken(@"method", method);	
			
			// and we must have a valid callback
			if (onRequest == null)
				throw new ArgumentNullException("onRequest");
			
			// look up the list of handlers for the specified hook point, and then look up the method in that list to 
			Hashtable requestHandlers = this[HttpRequestHookPoints.BeforeHttpRuntimeProcessing];

			// receive the list of handlers that is handling callback notification for methods in that list
			HttpRequestCancelEventHandler handlers = requestHandlers[method] as HttpRequestCancelEventHandler;

			// if the handler list is null
			if (handlers == null)
				// add the handlers into the list by the method we're registering for
				requestHandlers.Add(method, handlers);
				
			// now combine the callback with all of the existing handlers 
			handlers = (HttpRequestCancelEventHandler)Delegate.Combine(handlers, onRequest);

			// and finally store that list of callbacks using the method as the key in the list from which we retrieved this initially
			requestHandlers[method] = handlers;
		}
        /// <summary>
        /// Dispatches the request to each handler registered to receive notification of this request's method
        /// </summary>
        /// <param name="dispatcher"></param>
        /// <param name="request"></param>
        /// <param name="sender"></param>
        /// <param name="cancel"></param>
        private Delegate[] InternalDispatchRequest(object sender, ref HttpRequestCancelEventArgs e)
        {
            // look up the list of handlers for the specified hook point, and then look up the method in that list to
            Hashtable requestHandlers = this[HttpRequestHookPoints.BeforeHttpRuntimeProcessing];

            // receive the list of handlers that is handling callback notification for methods in that list
            HttpRequestCancelEventHandler handlers = requestHandlers[e.Request.Method] as HttpRequestCancelEventHandler;

            // there is a list of handlers waiting to be notified
            if (handlers == null)
            {
                return new Delegate[] {}
            }
            ;

            // extract the list of handlers to be notified when this method is received
            Delegate[] delegates = handlers.GetInvocationList();
            if (delegates == null)
            {
                return new Delegate[] {}
            }
            ;

            // enumerate each handler
            foreach (Delegate d in delegates)
            {
                try
                {
                    // notify the handler
                    ((HttpRequestCancelEventHandler)d)(sender, e);

                    // someone may have created a response that is ready to be sent for this event so no further processing is required
                    if (e.Response != null)
                    {
                        return(delegates);
                    }

                    // someone may have handled the request manually and there for this event is cancelled and no further processing is required
                    if (e.Cancel)
                    {
                        return(delegates);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }

            return(delegates);
        }
//		/// <summary>
//		/// Registers for notification for when the specified method is received in a HttpRequest
//		/// </summary>
//		/// <param name="method">The method notification will be registered for</param>
//		/// <param name="onRequest">The callback to be notified when/if the method is received</param>
//		public void RegisterForRequestMethodNotification(string method, HttpRequestEventHandler onRequest)
//		{
//			// we must have a valid method
//			HttpUtils.ValidateToken(@"method", method);
//
//			// and we must have a valid callback
//			if (onRequest == null)
//				throw new ArgumentNullException("onRequest");
//
//			// look up the list of handlers for the specified hook point, and then look up the method in that list to
//			Hashtable requestHandlers = this[HttpRequestHookPoints.AfterHttpRuntimeProcessing];
//
//			// receive the list of handlers that is handling callback notification for methods in that list
//			HttpRequestEventHandler handlers = requestHandlers[method] as HttpRequestEventHandler;
//
//			// if the handler list is null
//			if (handlers == null)
//				// add the handlers into the list by the method we're registering for
//				requestHandlers.Add(method, handlers);
//
//			// now combine the callback with all of the existing handlers
//			handlers = (HttpRequestEventHandler)Delegate.Combine(handlers, onRequest);
//
//			// and finally store that list of callbacks using the method as the key in the list from which we retrieved this initially
//			requestHandlers[method] = handlers;
//		}

        /// <summary>
        /// Unregisters for notification for when the specified method is received in a HttpRequest
        /// </summary>
        /// <param name="method">The method notification was registered for</param>
        /// <param name="onRequest">The callback to be notified when/if the method is received</param>
        public void UnregisterForRequestMethodNotification(string method, HttpRequestCancelEventHandler onRequest)
        {
            // we must have a valid method
            HttpUtils.ValidateToken(@"method", method);

            // and we must have a valid callback
            if (onRequest == null)
            {
                throw new ArgumentNullException("onRequest");
            }

            // look up the list of handlers for the specified hook point, and then look up the method in that list to
            Hashtable requestHandlers = this[HttpRequestHookPoints.BeforeHttpRuntimeProcessing];

            // receive the list of handlers that is handling callback notification for methods in that list
            HttpRequestCancelEventHandler handlers = requestHandlers[method] as HttpRequestCancelEventHandler;

            // if the handler list is null
            if (handlers != null)
            {
                // add the handlers into the list by the method we're registering for
                handlers = (HttpRequestCancelEventHandler)Delegate.Remove(handlers, onRequest);
            }

            // if there are still some handlers, and the list is zero length, remove the list entirely
            if (handlers != null)
            {
                if (handlers.GetInvocationList().Length == 0)
                {
                    requestHandlers.Remove(method);
                    return;
                }
            }

            // save the list of handlers for the next guy
            requestHandlers[method] = handlers;
        }
//		/// <summary>
//		/// Registers for notification for when the specified method is received in a HttpRequest
//		/// </summary>
//		/// <param name="method">The method notification will be registered for</param>
//		/// <param name="onRequest">The callback to be notified when/if the method is received</param>
//		public void RegisterForRequestMethodNotification(string method, HttpRequestEventHandler onRequest)
//		{
//			// we must have a valid method
//			HttpUtils.ValidateToken(@"method", method);	
//			
//			// and we must have a valid callback
//			if (onRequest == null)
//				throw new ArgumentNullException("onRequest");
//			
//			// look up the list of handlers for the specified hook point, and then look up the method in that list to 
//			Hashtable requestHandlers = this[HttpRequestHookPoints.AfterHttpRuntimeProcessing];
//
//			// receive the list of handlers that is handling callback notification for methods in that list
//			HttpRequestEventHandler handlers = requestHandlers[method] as HttpRequestEventHandler;
//
//			// if the handler list is null
//			if (handlers == null)
//				// add the handlers into the list by the method we're registering for
//				requestHandlers.Add(method, handlers);
//				
//			// now combine the callback with all of the existing handlers 
//			handlers = (HttpRequestEventHandler)Delegate.Combine(handlers, onRequest);
//
//			// and finally store that list of callbacks using the method as the key in the list from which we retrieved this initially
//			requestHandlers[method] = handlers;
//		}
		
		/// <summary>
		/// Unregisters for notification for when the specified method is received in a HttpRequest
		/// </summary>
		/// <param name="method">The method notification was registered for</param>
		/// <param name="onRequest">The callback to be notified when/if the method is received</param>
		public void UnregisterForRequestMethodNotification(string method, HttpRequestCancelEventHandler onRequest)
		{
			// we must have a valid method
			HttpUtils.ValidateToken(@"method", method);	
			
			// and we must have a valid callback
			if (onRequest == null)
				throw new ArgumentNullException("onRequest");

			// look up the list of handlers for the specified hook point, and then look up the method in that list to 
			Hashtable requestHandlers = this[HttpRequestHookPoints.BeforeHttpRuntimeProcessing];

			// receive the list of handlers that is handling callback notification for methods in that list
			HttpRequestCancelEventHandler handlers = requestHandlers[method] as HttpRequestCancelEventHandler;

			// if the handler list is null
			if (handlers != null)
				// add the handlers into the list by the method we're registering for
				handlers = (HttpRequestCancelEventHandler)Delegate.Remove(handlers, onRequest);

			// if there are still some handlers, and the list is zero length, remove the list entirely
			if (handlers != null)
				if (handlers.GetInvocationList().Length == 0)
				{
					requestHandlers.Remove(method);
					return;
				}
			
			// save the list of handlers for the next guy
			requestHandlers[method] = handlers;
		}