Execute a string of code as if it were a page

  • Thread starter Thread starter nick
  • Start date Start date
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
 
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/
 
Back
Top