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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:51:27+00:00 2026-05-11T01:51:27+00:00

I am building a fairly simple CMS. I need to intercept requests for the

  • 0

I am building a fairly simple CMS. I need to intercept requests for the majority of .aspx pages in my web application, in order to gain complete control over the output. In most cases, the output will be pulled from cache and will just be plain HTML.

However, there still are a couple of pages that I am going to need to use asp: controls on. I assume the best way for me to bypass a few particular requests would be to inherit System.Web.UI.PageHandlerFactory and just call the MyBase implementation when I need to (please correct me if I am wrong here). But how do I transfer all other requests to my custom handler?

  • 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. 2026-05-11T01:51:27+00:00Added an answer on May 11, 2026 at 1:51 am

    When I wrote a simple CMS, I had a difficult time using the PageHandlerFactory to get it to do what I wanted. In the end I switched to a IHttpModule.

    My module would first check to see if there was an .aspx file in the requested path. I’d only do that if the page has user controls on it or didn’t fit into the CMS for some reason. So if the file existed, it would return out of the module. After that it would look at the requested path and condense it into a ‘navigation tag.’ Thus ~/aboutus/default.aspx would become page.aspx?nt=aboutusdefault. page.aspx would load the proper content form the CMS. Of course, the redirect occurs server-side so the users/spiders never know anything different happened.

    using System; using System.Data; using System.Collections.Generic; using System.Configuration; using System.Reflection; using System.Text.RegularExpressions; using System.Web;  namespace MyCMS.Handlers {     /// <summary>     /// Checks to see if we should display a virutal page to replace the current request.     /// Code adapted from:     /// Rewrite.NET -- A URL Rewriting Engine for .NET     /// By Robert Chartier     /// http://www.15seconds.com/issue/030522.htm     /// </summary>     public class VirtualPageModule : IHttpModule {         /// <summary>         /// Init is required from the IHttpModule interface         /// </summary>         /// <param name='Appl'></param>         public void Init(System.Web.HttpApplication Appl) {             // make sure to wire up to BeginRequest             Appl.BeginRequest += new System.EventHandler(Rewrite_BeginRequest);         }          /// <summary>         /// Dispose is required from the IHttpModule interface         /// </summary>         public void Dispose() {             // make sure you clean up after yourself         }          /// <summary>         /// To handle the starting of the incoming request         /// </summary>         /// <param name='sender'></param>         /// <param name='args'></param>         public void Rewrite_BeginRequest(object sender, System.EventArgs args) {             // Cast the sender to an HttpApplication object             HttpApplication httpApp = (HttpApplication)sender;              // See if the requested file already exists             if (System.IO.File.Exists(httpApp.Request.PhysicalPath)) {                 // Do nothing, process the request as usual                 return;             }              string requestPath = VirtualPathUtility.ToAppRelative(httpApp.Request.Path);              // Organic navigation tag (~/aboutus/default.aspx = nt 'aboutusdefault')             Regex regex = new Regex('[~/\\!@#$%^&*()+=-]');             requestPath = regex.Replace(requestPath, string.Empty).Replace('.aspx', string.Empty);             string pageName = '~/page.aspx';             string destinationUrl = VirtualPathUtility.ToAbsolute(pageName) + '?nt=' + requestPath;             SendToNewUrl(destinationUrl, httpApp);         }          public void SendToNewUrl(string url, HttpApplication httpApp) {             applyTrailingSlashHack(httpApp);             httpApp.Context.RewritePath(                 url,                 false // RebaseClientPath must be false for ~/ to continue working in subdirectories.             );         }          /// <summary>         /// Applies the trailing slash hack. To circumvent an ASP.NET bug related to dynamically         /// generated virtual directories ending in a trailing slash (/).         /// As described by BuddyDvd:         /// http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105061         /// </summary>         /// <param name='httpApp'>The HttpApplication.</param>         /// <remarks>         /// Execute this function before calling RewritePath.         /// </remarks>         private void applyTrailingSlashHack(HttpApplication httpApp) {             if (httpApp.Request.Url.AbsoluteUri.EndsWith('/') && !httpApp.Request.Url.AbsolutePath.Equals('/')) {                 Type requestType = httpApp.Context.Request.GetType();                 object clientFilePath = requestType.InvokeMember('ClientFilePath', BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty, null, httpApp.Context.Request, null);                 string virtualPathString = (string)clientFilePath.GetType().InvokeMember('_virtualPath', BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, null, clientFilePath, null);                 clientFilePath.GetType().InvokeMember('_virtualPath', BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField, null, clientFilePath, new object[] { virtualPathString });                 requestType.InvokeMember('_clientFilePath', BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField, null, HttpContext.Current.Request, new object[] { clientFilePath });                 object clientBaseDir = requestType.InvokeMember('ClientBaseDir', BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty, null, httpApp.Context.Request, null);                 clientBaseDir.GetType().InvokeMember('_virtualPath', BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField, null, clientBaseDir, new object[] { virtualPathString });                 requestType.InvokeMember('_clientBaseDir', BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField, null, HttpContext.Current.Request, new object[] { clientBaseDir });             }         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 78k
  • Answers 79k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Try this. May 11, 2026 at 3:58 pm
  • added an answer You should use an inline tag like <span> May 11, 2026 at 3:58 pm
  • added an answer Does it have to be done within vim? Could you… May 11, 2026 at 3:58 pm

Related Questions

I am building a small website for fun/learning using a fairly standard Web/Service/Data Access
I am about to build a piece of a project that will need to
Okay, so I'm sure plenty of you have built crazy database intensive pages... I
I am building a Web service using WCF as a way to provide access

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.