views:

27

answers:

0

the tl;dr version: using Server.Execute() to retrieve the raw html of a web page returns an empty string if called during a callback, but works fine during a postback.

I am writing some calendaring functionality where I need to send out notification emails to attendees when an appointment is created, changed, or deleted. The text of the notification emails are aspx pages that are retrieved through a call to Server.Execute(); the pages take an appointment id as a query string parameter and build the text of the email (start date, end date, location, etc) by retrieving the appointment record from a database. The code to retrieve the html is pretty straightforward:

StringWriter stringWriter = new StringWriter();
HttpContext.Current.Server.Execute(emailUrl, stringWriter);

string rawHtml = stringWriter.ToString();

All is well and good if you create or edit an appointment through a form interface, which updates the database and sends the emails during postback. However, I purchased a third party calendaring package (DayPilot) that mimics Outlook -- you can drag appointments to another day, resize them, etc. All of this functionality is done through callbacks. During the callback, I update the database and then attempt to send out the notification email that the appointment date/time has changed. The above code executes fine (I put a breakpoint on the notification email page so it is being executed) but stringWriter contains an empty string instead of the html of the page. Again, this is just during callbacks; it retrieves the email html correctly during postback.

Is there some sort of limitation that prevents Server.Execute retrieving the response during callbacks?

EDIT:

GRRR...setting the preserveForm parameter to false made it work. Never mind...

HttpContext.Current.Server.Execute(emailUrl, stringWriter, false);