private void VerifyRenderedBodyOrSections()
{
// The _body will be set within a layout page because PageContext.BodyAction was set by RenderSurrounding,
// which is only called in the case of rendering layout pages.
// Using RenderPage will not result in a _body being set in a partial page, thus the following checks for
// sections should not apply when RenderPage is called.
// Dev10 bug 928341
if (_body != null)
{
if (SectionWritersStack.Count > 1 && PreviousSectionWriters != null && PreviousSectionWriters.Count > 0)
{
// There are sections defined. Check that all sections have been rendered.
StringBuilder sectionsNotRendered = new StringBuilder();
foreach (var name in PreviousSectionWriters.Keys)
{
if (!_renderedSections.Contains(name))
{
if (sectionsNotRendered.Length > 0)
{
sectionsNotRendered.Append("; ");
}
sectionsNotRendered.Append(name);
}
}
if (sectionsNotRendered.Length > 0)
{
throw new HttpException(String.Format(CultureInfo.CurrentCulture, WebPageResources.WebPage_SectionsNotRendered, VirtualPath, sectionsNotRendered.ToString()));
}
}
else if (!_renderedBody)
{
// There are no sections defined, but RenderBody was NOT called.
// If a body was defined, then RenderBody should have been called.
throw new HttpException(String.Format(CultureInfo.CurrentCulture, WebPageResources.WebPage_RenderBodyNotCalled, VirtualPath));
}
}
}