2

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

3 Answers 3

1

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
  • I don't think that's what he's asking. I think he wants to capture the rendered output of the .aspx page and do something with it other than serve it up to the client browser. Feb 20, 2013 at 20:14
  • I think I didn't express myself clearly. I've added an example of what I'm trying in my question above
    – sanjay
    Feb 21, 2013 at 12:31
1

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 think I didn't express myself clearly. I've added an example of what I'm trying in my question above
    – sanjay
    Feb 21, 2013 at 12:31
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
  • Thanks for your answer, however I'm looking for something else. I want to be able to analyze them for possible scripting vulnerabilities. The .ToString I gave was just an example. It could be any construct there (<%# Eval("MeetingName")%>). Anything between the asp tags like <% ... %> whether it be an input box or table or anything fetched from database ... I want to be able to find out.
    – sanjay
    Feb 23, 2013 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.