public void Execute()
{
// Setup the output to a string builder
var sb = new StringBuilder();
Output = new StringWriter(sb);
// Run the start page
if (StartPage != null)
StartPage.Execute(this);
Context.CurrentView = this;
try
{
// Execute the page view
OnExecute();
}
finally
{
Context.CurrentView = null;
}
// Clean up the output writer
Output.Flush();
Output = null;
// Capture the output
GeneratedBody = sb.ToString();
// Apply layout view
if (Layout != null)
{
IViewTemplate layoutView = Context.Application.ViewService.LoadViewTemplate(Context.Application.MapPath(Layout));
layoutView.Render(Context, Model, this, false);
}
else
{
// Write the output
Response.Write(GeneratedBody);
}
}