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

Related Questions

We are building a fairly complex application that we need to be able to
I'm building a fairly simple PHP script that will need to send some emails
My question is fairly simple, in an app I'm building, there is no need
Building an application which started as fairly simple, but now got pretty complicated. I
I'm building a fairly simple Android app (sdk revision 14: ICS) which allows users
This is fairly simple but I cant work it out. I'm building a wordpress
I am fairly new to Flotr2 and I have just been building some simple
I'm building a fairly large enterprise application made in python that on its first
I am building an application for which I need to periodically get information about
I'm building a (very) simple FTP app in Cocoa, and I need to store

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.