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 7039113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:45:28+00:00 2026-05-28T01:45:28+00:00

I need to do routing in an existing asp.net app – not an asp.net

  • 0

I need to do routing in an existing asp.net app – not an asp.net mvc (yeah I know I should convert but let’s say it’s not possible right now so don’t tell me 🙂 ) – how can I do routing to a normal class instead of an aspx page as all sample code I see is always with aspx page like here:

http://msdn.microsoft.com/en-us/magazine/dd347546.aspx

To precise, I want to do a bit like in MVC Controller routing : the controller for example product is a pure class you access through http://domain.com/product

  • 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-28T01:45:28+00:00Added an answer on May 28, 2026 at 1:45 am

    ASP.NET MVC and ASP.NET Web Forms share the same routing infrastructure in that both frameworks ultimately need to come up with an IHttpHandler to handle the HTTP request:

    The IHttpHandler interface has been a part of ASP.NET since the
    beginning, and a Web Form (a System.Web.UI.Page) is an IHttpHandler.

    (From the MSDN article linked in the question)

    In ASP.NET MVC the System.Web.Mvc.MvcHandler class is used, which then delegates to a controller for further handling of the request. In ASP.NET Web Forms usually the System.Web.UI.Page class that represents an .aspx file is used, but a pure IHttpHandler associated with .ashx file can also be used.

    So you can route to an .ashx handler as an alternative to an .aspx Web Forms page. Both implement IHttpHandler (as does MvcHandler), but with the former that’s all it does. And that’s as close as you can get to a ‘pure class’ handling a (routed) request. And since the handler part is just an interface, you are free to inherit from your own class.

    <%@ WebHandler Language="C#" Class="LightweightHandler" %>
    
    using System.Web;
    
    public class LightweightHandler : YourBaseClass, IHttpHandler
    {
      public void ProcessRequest(HttpContext context)
      {
        context.Response.ContentType = "text/plain";
        context.Response.Write("Hello world!");
      }
    
      public bool IsReusable { get { return false; } }
    }
    

    Notice that an IRouteHandler just needs to return an instance of IHttpHandler:

    public IHttpHandler GetHttpHandler(RequestContext requestContext);
    

    You may need to jump through some hoops to instantiate your handler using the BuildManager* if you use .ashx files. If not, you can just new up an instance of your class and return it:

    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
      // In case of an .ashx file, otherwise just new up an instance of a class here
      IHttpHandler handler = 
        BuildManager.CreateInstanceFromVirtualPath(path, typeof(IHttpHandler)) as IHttpHandler;
    
      // Cast to your base class in order to make it work for you
      YourBaseClass instance = handler as YourBaseClass;
      instance.Setting = 42;
      instance.DoWork();
    
      // But return it as an IHttpHandler still, as it needs to do ProcessRequest
      return handler;
    }
    

    See the answers to this question for much more in-depth analysis of routing pure IHttpHandlers: Can ASP.NET Routing be used to create “clean” URLs for .ashx (IHttpHander) handlers?

    **I’m not entirely sure about the BuildManager example, someone please correct me if I got that part wrong*

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

Sidebar

Related Questions

Do the POST parameters need some sort of routing configuration in ASP.NET MVC? If
I need to use routing with parameters in my ASP.NET application. public class Global
I have an existing site that I'd like to convert to use routing, and
I need to do some special routing in cake, but can't for the life
I have created an otherwise empty ASP.NET MVC 3 application with 2 controllers, HomeController
My question is regarding Page Routing in an ASP.net (VB) Web Forms website. I
I have the following code using normal Zend routing and I need to convert
I'm working on some routing functionality in an Android app, and need to access
I use asp.net 4, c# and Routing for my web site. My Route result
I need to create a patching routine for my application, it's really small but

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.