views:

88

answers:

4

In a plain .asp file, any content outside of <% %> tags is sent directly to the output buffer. Additionally, an expression in <%= %> tags is evaluated and sent to the output buffer.

I want to redirect it so that, in some context that I establish, the result of those two constructs is instead sent to a buffer that I control. If possible, I'd like to be able to do this dynamically, so that I can redirect the output to different buffers at runtime.

The problem is open-ended, largely because I'll be planning what I'm building around this solution. I could use any way that exists to capture this output. Performance and ease of use are not major considerations.

This is a sequel to this question, in which I try one possible solution that turns out to not work.

A: 

well for the <%=%> thing you could write your own function:

function [=](val)
    response.write val
    ' do anything you want with val
end function

the other thing is not possible i think. but you could use the <%=%> construct for every output you want to redirect...

ulluoink
Does not work. = is not a valid identifier, and the bracket notation doesn't do anything to turn the <%= %> syntax into a call to the = function.
Thom Smith
ok sorry for that. you have to use <%[=]"teststring"%> for the call. mhh that doesn't help you very much does it?
ulluoink
A: 

This isn't a real solution, but it's the best I can come up with:

    <% sub foo %>
            <h1>Hello, World!</h1>
    <% end sub %>

Then the sub's contents can be written to the Response if and when they are needed. The sub can be manipulated using GetRef. This will pollute the global namespace with subs; they can't even be methods since GetRef won't work with them. (The first time I tested this, I accidentally stomped on an existing function.)

I'd really like to improve on this, if it's possible. I'd appreciate any feedback.

Thom Smith
+1  A: 

I don't think that you can do this in ASP. You could try to create an ISAPI filter that will monitor the response for some placeholders that you put in there an do something different with the data between the placeholders.
I am not sure exactly what your end goal is so I do not know if this would work for you.

Mike
+1  A: 

In effect, you are trying to rewrite the asp.dll ISAPI filter. If you really wanted to do this, you could try to write a wrapper DLL around the asp.dll which overrides its WriteClient function. This will not be straightforward and begs the question of what you trying to accomplish.

A far simpler solution would be to avoid using <% %> altogether and instead assemble the entire page (or most of it) in code so that your page is nothing more than:

<html>
<%=OutputHtml()%>
</html>

In this way, you can have total control over what gets outputted and when.

Thomas