ASP.NET Communicate between two ASHX handlers
<p>In a small ASP.NET 2.0 web-application, I have two ASHX handlers (one sync, one async) to deal with COMET style messaging. The sync handler takes an addressee and a message, while the async handler holds the "sleeping" connections to all clients.</p>

<p>The Problem: I need to populate some sort of message queue in a shared state. However, even though both handlers are in the same namespace, I can't invoke any (static or non-static) method in the other. I can't even access static methods in the Global-class from any of the handlers. This line simply gives me a compiler error:</p>

<pre><code>Global.SendMessage(recipient, context.Request["message"]);
</code></pre>

<p>Compiler Error Message: CS0103: The name 'Global' does not exist in the current context</p>

<p>I'm not exactly sure in which context I am.</p>

<p>The handlers are written directly into a .ashx file like this:</p>

<pre><code>&lt;%@ WebHandler Language="C#" Class="MyApp.MessageHandler" %&gt;

using System;
using System.Web;

namespace MyApp
{
    public class MessageHandler : IHttpHandler
</code></pre>

<p>Any hints?</p>

<p><strong>EDIT:</strong></p>

<p>As suggested, I put the class in a code behind file, so the mark up in the ashx file looks like this:</p>

<pre><code>&lt;%@ WebHandler Language="C#" Class="MyApp.MessageHandler" CodeBehind="MessageHandler.ashx.cs" %&gt;
</code></pre>

<p>The code behind file is present, with the same name. However, this gives me an error as well:</p>

<blockquote>
  <p>Parser Error Message: Could not create type
  'MyApp.MessageHandler'.
  Source Error: 
  Line 1:  &lt;%@ WebHandler Language="C#" Class="MyApp.MessageHandler"
  CodeBehind="MessageHandler.ashx.cs" %></p>
</blockquote>

<p>The MessageHandler class:</p>

<pre><code>using System;
using System.Web;

namespace MyApp
{
    public class MessageHandler : IHttpHandler
    {
        /*public MessageHandler()
        {
        }
        */
        #region IHttpHandler Members
        public bool IsReusable
        {
            get { return true; }
        }
        //Called to induce new message from external
        public void ProcessRequest(HttpContext context)
        {
            string recipient = context.Request["recipient"];
            context.Response.Write(recipient);
            if (recipient == "all" || string.IsNullOrEmpty(recipient))
            {
                Global.BroadcastMessage(context.Request["message"]);
            }
            else
            {
                Global.SendMessage(recipient, context.Request["message"]);
            }
        }
        #endregion
    }
}
</code></pre>

<p>One sample method in the Global class:</p>

<pre><code>  public static void SendMessage(string recipient, string message)
    {
        Client client;
        if (clients.ContainsKey(recipient))
        {

            if (clients.TryGetValue(recipient, out client))
            {
                client.Message = message;
                client.SetCompleted(true);
            }
        }
    }
</code></pre>
