Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6190753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:38:41+00:00 2026-05-24T02:38:41+00:00

In a small ASP.NET 2.0 web-application, I have two ASHX handlers (one sync, one

  • 0

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.

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:

Global.SendMessage(recipient, context.Request["message"]);

Compiler Error Message: CS0103: The name ‘Global’ does not exist in the current context

I’m not exactly sure in which context I am.

The handlers are written directly into a .ashx file like this:

<%@ WebHandler Language="C#" Class="MyApp.MessageHandler" %>

using System;
using System.Web;

namespace MyApp
{
    public class MessageHandler : IHttpHandler

Any hints?

EDIT:

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

<%@ WebHandler Language="C#" Class="MyApp.MessageHandler" CodeBehind="MessageHandler.ashx.cs" %>

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

Parser Error Message: Could not create type
‘MyApp.MessageHandler’.
Source Error:
Line 1: <%@ WebHandler Language=”C#” Class=”MyApp.MessageHandler”
CodeBehind=”MessageHandler.ashx.cs” %>

The MessageHandler class:

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
    }
}

One sample method in the Global class:

  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);
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:38:42+00:00Added an answer on May 24, 2026 at 2:38 am

    If you write your code in code behind files for ashx then you can call static/non-static methods across the handlers as that code gets compiled when you build the project, where as the code in ashx file get compiled on the fly when the handlers receive a request and hence it cannot be called during the normal project build process as it not yet available to compiler

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a favicon.ico in my asp.net web application. It is small but how
I have to create a small asp.net-application. The last such web-application I have built
I have a small web application based on asp.net 2010 that manages invoices. After
I'm working on a relatively small asp.net web application and am wondering if there
I'm building a small web application with ASP.NET MVC 2, using db4o as a
I have an ASP.NET MVC web application which is hosted by an external provider,
I am trying to migrate a small ASP.NET 'web site' (not web application) to
I'm using forms authentication on a very small ASP.NET web app (Web Forms) in
I'm building small web shop with asp.net mvc and Structuremap ioc/di. My Basket class
I am doing simple forms authentication for a small ASP.NET (3.5, C#) application and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.