Everything about my daily life as a programmer/Electrical Engineer!

Running Asp.Net without a webserver

If you ever need to generate web pages that are static (for reporting etc) you often find yourself emitting html. Turns out Asp.Net is perfectly suited to do this.

class Program
static void Main(string[] args)
Page pg = new Page();
Label lbl = new Label();
lbl.Text = "Look ma no web server";
StringWriter sw=new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);

All thats left is to either save the file or embed the file in the embedded ie window. You can leverage all the cool controls of asp.net but be sure to remember that there is no way this can postback.

No comments: