Execute a string of code as if it were a page

N

nick

Hi,

I wondering if it is possible in asp.net to somehow execute a string
of code as if it were a page on the server. That is to say, if I
executed the following code which resided in an aspx page

<html>
<body>
<% Response.Write("Hi.") %>
</body>
</html>

the output would be

<html>
<body>
Hi
</body>
</html>

Is there some way I could execute the asp.net from above without it
being in an actual page? Can I send some server method a string and
get the output?

Thanks for any help,

Nick
 
T

TJS

build the string , populate it with dynamic content and use,
response.write("mystring")
 
R

Rick Strahl [MVP]

Hey Nick,


Not directly...

What you can do though is create a file on disk, then use Server.Execute()
to 'run' that page. You can delete it when you're done.

IOW:

Take your string
dump to file with ASPX extensino
Server.Execute() to the page with an HtmlTextWriter
Return retrieve the HtmlTextWriter and the result string
Delete the page you created

Be aware though that this causes memory to be used as this new class (the
ASPX) page is created and compiled into an assembly and laoded. If you did
this a lot during processing you'd eat up memory really quickly.

What you should do instead is build a few generic pages that you can use
over and over and do some sort of processing inside those pages that might
be more dynamic.


+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/webblog/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top