Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

257966: Parameterless overload of WebPage::ExecutePageHierarchy throws

when called.
  • Loading branch information...
commit a565f101ffe8d28a415668cad7f558585efc0cc6 1 parent 5391de5
@pranavkm pranavkm authored
View
11 src/System.Web.WebPages/Resources/WebPageResources.Designer.cs
@@ -349,6 +349,15 @@ internal class WebPageResources {
}
/// <summary>
+ /// Looks up a localized string similar to ExecutePageHierarchy cannot be invoked if PageContext is null..
+ /// </summary>
+ internal static string WebPage_ExecutePageHierarchyCannotBeInvoked {
+ get {
+ return ResourceManager.GetString("WebPage_ExecutePageHierarchyCannotBeInvoked", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to The following file could not be rendered because its extension &quot;{0}&quot; might not be supported: &quot;{1}&quot;..
/// </summary>
internal static string WebPage_FileNotSupported {
@@ -438,4 +447,4 @@ internal class WebPageResources {
}
}
}
-}
+}
View
3  src/System.Web.WebPages/Resources/WebPageResources.resx
@@ -216,6 +216,9 @@
<data name="WebPage_CannotRequestDirectly" xml:space="preserve">
<value>The file "{0}" cannot be requested directly because it calls the "{1}" method.</value>
</data>
+ <data name="WebPage_ExecutePageHierarchyCannotBeInvoked" xml:space="preserve">
+ <value>ExecutePageHierarchy cannot be invoked if PageContext is null.</value>
+ </data>
<data name="WebPage_FileNotSupported" xml:space="preserve">
<value>The following file could not be rendered because its extension "{0}" might not be supported: "{1}".</value>
</data>
View
6 src/System.Web.WebPages/WebPage.cs
@@ -2,6 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Web.WebPages.Html;
+using System.Web.WebPages.Resources;
using System.Web.WebPages.Scope;
namespace System.Web.WebPages
@@ -65,6 +66,11 @@ public static void RegisterPageExecutor(IWebPageRequestExecutor executor)
public override void ExecutePageHierarchy()
{
+ if (PageContext == null)
+ {
+ // The ExecutePageHierarchy in WebPageBase assumes a non-null PageContext.
+ throw new InvalidOperationException(WebPageResources.WebPage_ExecutePageHierarchyCannotBeInvoked);
+ }
using (ScopeStorage.CreateTransientScope(new ScopeStorageDictionary(ScopeStorage.CurrentScope, PageData)))
{
ExecutePageHierarchy(_executors);
View
10 test/System.Web.WebPages.Test/WebPage/WebPageTest.cs
@@ -32,6 +32,16 @@ public void CreatePageFromVirtualPathAssignsVirtualPathFactory()
}
[Fact]
+ public void ExecutePageHierarchyThrowsIfPageContextIsNotSet()
+ {
+ // Arrange
+ var page = new Mock<WebPage>() { CallBase = true };
+
+ // Act and Assert
+ Assert.Throws<InvalidOperationException>(() => page.Object.ExecutePageHierarchy(), "ExecutePageHierarchy cannot be invoked if PageContext is null.");
+ }
+
+ [Fact]
public void NormalizeLayoutPagePathTest()
{
var layoutPage = "Layout.cshtml";
Please sign in to comment.
Something went wrong with that request. Please try again.