问题
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?
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/10215284/how-can-i-programmatically-modify-an-aspx-file-content-before-the-handler-handle