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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:06:28+00:00 2026-05-22T13:06:28+00:00

What I’m trying to do is create (or perhaps one already exists) a HTTPHandler

  • 0

What I’m trying to do is create (or perhaps one already exists) a HTTPHandler that will filter the HTML generated ASP.NET to use the content delivery network (CDN). For example, I want to rewrite references such as this:

/Portals/_default/default.css

to

http://cdn.example.com/Portals/_default/default.css

I’m perfectly happy using RegEx to match the initial strings. Such a regex patterns might be:

href=['"](/Portals/.+\.css)

or

src=['"](/Portals/.+\.(css|gif|jpg|jpeg))

This is a dotnetnuke site and I don’t really have control over all the HTML generated so that’s why I want to do it with an HTTPHandler. That way the changes can be done post-page generation.

  • 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-22T13:06:29+00:00Added an answer on May 22, 2026 at 1:06 pm

    You could write a response filter which can be registered in a custom HTTP module and which will modify the generated HTML of all pages running the regex you showed.

    For example:

    public class CdnFilter : MemoryStream
    {
        private readonly Stream _outputStream;
        public CdnFilter(Stream outputStream)
        {
            _outputStream = outputStream;
        }
    
        public override void Write(byte[] buffer, int offset, int count)
        {
            var contentInBuffer = Encoding.UTF8.GetString(buffer);
    
            contentInBuffer = Regex.Replace(
                contentInBuffer, 
                @"href=(['""])(/Portals/.+\.css)",
                m => string.Format("href={0}http://cdn.example.com{1}", m.Groups[1].Value, m.Groups[2].Value)
            );
    
            contentInBuffer = Regex.Replace(
                contentInBuffer,
                @"src=(['""])(/Portals/.+\.(css|gif|jpg|jpeg))",
                m => string.Format("href={0}http://cdn.example.com{1}", m.Groups[1].Value, m.Groups[2].Value)
            );
    
            _outputStream.Write(Encoding.UTF8.GetBytes(contentInBuffer), offset, Encoding.UTF8.GetByteCount(contentInBuffer));
        }
    }
    

    and then write a module:

    public class CdnModule : IHttpModule
    {
        void IHttpModule.Dispose()
        {
        }
    
        void IHttpModule.Init(HttpApplication context)
        {
            context.ReleaseRequestState += new EventHandler(context_ReleaseRequestState);
        }
    
        void context_ReleaseRequestState(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Filter = new CdnFilter(HttpContext.Current.Response.Filter);
        }
    }
    

    and register in web.config:

    <httpModules>
      <add name="CdnModule" type="MyApp.CdnModule, MyApp"/>
    </httpModules>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.