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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:34:41+00:00 2026-06-01T09:34:41+00:00

Here’s the main question I guess : Is there a .NET way to get

  • 0

Here’s the “main question” I guess:

Is there a “.NET way” to get at a request very early on (either via HttpHandler or HttpModule) and inject standard asp.net markup, either in the form of standard controls, or user/custom controls, and have the framework treat it like a page that it is compiling dynamically?

More Background

Ok, so there’s this custom CMS we use that does a great job of building fairly complicated sites. It has a nice templating system, user permissions, easy to install, etc. However, one feature we want to add is being able to add dynamic content.

After the CMS goes out and does “its thing” the result is essentially a giant HTML string that gets sent back in the response. The rendering engine is contained in a class that handles this “cms stuff”. Right now this happens in a standard page lifecycle, but there’s no reason it can’t be called independently.

I’ve been able to get close with both a httpHandler and httpModule, but the problem is that what I really need is to take the “cms html string”, add in my own .net controls, and then have the framework take that new string and build a control tree from it (along with a viewstate, etc).

The closest I got was with the HttpModule which during PreRequestHandlerExecute attached a filter to the Response. This filter just looked for places to replace {{replaceme}} with a label tag markup (as a proof-of-concept…example below). I thought this would work since from what I had read this was before the control tree was created, but all that happened was the asp.net markup was written to the page (not rendered by .NET).

Another thing I’ve tried is to take complete control via an HttpHandler. This almost worked as well (also an example below)…the problem here is that while I can build my own control tree, and even execute an ascx control, there is no place to merge all of these things together (remember I already have an entire html document string, I’m trying to merge it at runtime and pass it to .NET).

I feel like I’m very close but missing some very easy way to pass most of this work off to .NET…

Httpmodule

    private void PreRequestHandlerExecute(Object source, EventArgs e)
    {
        HttpApplication application = (HttpApplication)source;
        HttpContext context = application.Context;

        context.Response.Filter = new PageFilter(context.Response.Filter);
    }

Filter (From a SO example I think)

    public override void Write(byte[] buffer, int offset, int count)
    {
        string strBuffer = System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count);

        // ---------------------------------
        // Wait for the closing </html> tag
        // ---------------------------------
        Regex eof = new Regex("</html>", RegexOptions.IgnoreCase);

        if (!eof.IsMatch(strBuffer))
        {
            responseHtml.Append(strBuffer);
        }
        else
        {
            responseHtml.Append(strBuffer);
            string finalHtml = responseHtml.ToString();

            finalHtml = finalHtml.Replace("{{replaceme}}", @"<asp:Label id=""lblMyTest"" runat=""server"" Text=""This is a label that was replaced by my responsefilter"" />");

            // Transform the response and write it back out

            byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(finalHtml);

            responseStream.Write(data, 0, data.Length);
        }
    }

The Test HttpHandler

    public void ProcessRequest(HttpContext context)
    {

        MyBasePage page = new MyBasePage();
        Test tpage = (Test)BuildManager.CreateInstanceFromVirtualPath("~/Test.ascx", typeof(Test));

        var htmlform = new System.Web.UI.HtmlControls.HtmlForm();
        var panel = new Panel();

        panel.Controls.Add(new Label() { Text = "Hello World" });
        panel.Controls.Add(tpage);

        htmlform.Controls.Add(panel);
        page.Controls.Add(htmlform);
        page.ProcessRequest(context);
    }
  • 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-06-01T09:34:42+00:00Added an answer on June 1, 2026 at 9:34 am

    You may have a lot of trouble trying to do this. If I understand you, you have a chunk of HTML that comes out of the CMS, and you want to turn that back into a control tree, which you can merge with more controls (from ASP.Net markup) and then generate the final HTML.

    But that’s the opposite of what ASP.Net does. It parses markup with ASP.Net controls to generate a control tree, and then generates HTML from that control tree. Nothing in ASP.Net parses arbitrary HTML. I think you’d need to completely re-write the .aspx handler, duplicating all its parsing and tree building functions.

    I would try to find another way to implement this using your CMS. You’re subverting the system, and that could only lead to a very hard to maintain mess.

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

Sidebar

Related Questions

here is a debatable question which i want to achieve not sure how .
Here is the piece of code which I use to get the count from
Here is the stacktrace: 04-10 18:09:36.393: E/AndroidRuntime(26592): FATAL EXCEPTION: main 04-10 18:09:36.393: E/AndroidRuntime(26592): java.lang.RuntimeException:
Here an example of my checkbox list http://jsfiddle.net/YnM2f/ Let's say I check on G
Here a simple question : What do you think of code which use try
Here's what I'm trying to do... It's quite simple and obviously there must be
Here is my question. I am having this simple menu. <div id=menu> <ul> <li>
Here is a working version http://jsfiddle.net/tH78C/ Here is a broken version (Zooming widget is
Here is my problem...I have a page that loads a list of clients and
Here is some code I made :) @echo off set source=R:\Contracts\ set destination=R:\Contracts\Sites\ ROBOCOPY

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.