can I execute an aspx file in a class library and get the result as a string?
I have an c# Class Libr开发者_JAVA百科ary where I need some dynamic template based text. Instead of inventing my own template parser I thought I could create an aspx file in my project that is executed at runtime and, instead of viewing the output in a browser, I want a StreamReader or string object that holds the result.
Is that possible? And if yes, how do I do this?
You're going to struggle more than is necessary with this approach. You'd need an ASP.NET host like IIS.
Personally, I'd recommend an existing template processor. I've heard (on a Hanselminutes or DotNetRocks podcast, I think) that you might even be able to host the T4 system in your application. I'll have a look and see if I've remembered that correctly.
Update
Here's a link on hosting T4 templating in your application.
ASP.Net is designed to be run in a web server engine - you would also have to deploy this to make it work.
Calling ASPX Pages from a Library would be possible (see Cassini WebServer) but I would recommend another tool:
http://www.codeproject.com/KB/cs/T4BasedCodeGenerator.aspx
We use it in our Project - slightly adapted for our needs
精彩评论