0

The reason I need to modify the content of an aspx (not physically, but change the content in the memory) is because there are certain custom tags I made needs to be parsed to the correct data before the entire aspx is handled by the HttpHandler.

Is there a way for that?

Lida Weng
  • 476
  • 6
  • 20

2 Answers2

0

You can use Response Filters (HttpFilter) and modify content on the fly, basically after response is formed, before EndRequest your filter is called (it's a stream descendant) and you can modify it as you wish. In the HttpModule, Init method you got to install HttpFilter (Response.Filter) and it will be called for that request.

Here is a good article :

http://aspnetresources.com/articles/HttpFilters

UPDATE: Maybe this is a case of XY Problem, and you can solve your problem with simple server control that will render these custom tags properly.

Community
  • 1
  • 1
Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
  • thanks - but I need to parse the document before it is handled by aspx handler - any sugestions? – Lida Weng Apr 18 '12 at 18:41
  • I don't understand, what do you mean by document ? There is nothing to parse before Request is handled. – Antonio Bakula Apr 18 '12 at 18:44
  • Probably he wants to see the content of an ASPX file as one string, modify it and then let it flow through the ASP.NET pipeline for being interpreted as an actual ASPX page. – Uwe Keim Apr 18 '12 at 18:57
  • Well if that is the case, it's IMO wrong approach to the problem, if nothing else regarding to performance, and it's much more complicated then dealing with that custom tag in simple server control. – Antonio Bakula Apr 18 '12 at 19:06
0

you can use the Render event

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)


    Dim sw As New System.IO.StringWriter
    Dim hw As New HtmlTextWriter(sw)
    MyBase.Render(hw)
    Dim html As String = sw.ToString()

    ' html = html.Replace() etc to change your html code in here

    writer.Write(html)
End Sub

EDIT i see you want to inject mark up dynamically before asp.net handles the aspx, maybe the FileLevelPageControlBuilder Class is of use

Symeon Breen
  • 1,531
  • 11
  • 25
  • thanks - but I need to parse the document before it is handled by aspx handler - so basically it's much earlier before the page events. – Lida Weng Apr 18 '12 at 18:42