I want to know if it is possible to write to a log/text file dynamically generated HTML in asp.net tags in an .aspx page using HTTP modules.
By dynamically generated HTML, I mean the html content that asp.net generates in response to statements between the tags <% %> or <%# %> or <%$ %>.
So when asp.net renders a page, it essentially converts everything into HTML. There is some static html written in the asp.net page, rest is what i call dynamically genrated HTML. My goal is to dump somewhere all the dynamically generated HTML content.
Can it be done using HTTP Modules or any other mechanism ?
Example:
If the .aspx page is like this
…
<td>Total Credit Line </td>
<td><%=creditLimit.ToString("C")%></td>
…
I want the HTTP Module to write in a log file, the HTML rendered by the <%=creditLimit.ToString(“C”)%> asp tag and all other asp tags on the page. The HTTP Module would be generic and can be added to any IIS website.
Note that there would be no difference in the output that is seen by a browser.
0
You can dump any valid html or text output you want into a LiteralControl, and it will be passed directly into the output page without being processed on the ASP.NET server.
2
If I understand you correctly than Yes
At a fundamental level a webpage no different than a Webservice. They both go over HTTP and return a Header with some data in the Body.
You just need to access your .net page as would any Http client, that would return the rendered HTML just like a web service returns HTML.
See: How to Request Data Using the WebRequest Class
1
I want the HTTP Module to write in a log file, the HTML rendered by
the <%=creditLimit.ToString(“C”)%> asp tag and all other asp tags on
the page. The HTTP Module would be generic and can be added to any IIS
website. Note that there would be no difference in the output that is
seen by a browser.
Putting aside why you would want to do this…
I would add a method to the Object called ToStringAndLog()
The method would log it then return this.ToString()
When you want an Log a Particular ToString()
action use ToStringAndLog()
or always use ToStringAndLog()
and add a flag to the object that turns Logging on and off.
You could Override the ToString()
if you wanted to add this functionality to a ton of existing code.
1