Allow AddPageRoute to route to pages root. (#6412)

* Allow AddPageRoute to route to pages root.
Fixes #6338
This commit is contained in:
Pranav K 2017-06-20 12:33:33 -07:00 committed by GitHub
parent f824704741
commit c89f0a1e43
4 changed files with 18 additions and 2 deletions

View File

@ -193,9 +193,9 @@ namespace Microsoft.Extensions.DependencyInjection
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(pageName));
}
if (string.IsNullOrEmpty(route))
if (route == null)
{
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(route));
throw new ArgumentNullException(nameof(route));
}
options.Conventions.Add(new PageConvention(pageName, model =>

View File

@ -1037,6 +1037,19 @@ Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary`1[AspNetCore._InjectedP
Assert.StartsWith(expected, response.Trim());
}
[Fact]
public async Task PagesCanByRoutedToApplicationRoot_ViaAddPageRoute()
{
// Arrange
var expected = "Hello from NotTheRoot";
// Act
var response = await Client.GetStringAsync("");
// Assert
Assert.StartsWith(expected, response.Trim());
}
private async Task AddAntiforgeryHeaders(HttpRequestMessage request)
{
var getResponse = await Client.GetAsync(request.RequestUri);

View File

@ -0,0 +1,2 @@
@page
Hello from NotTheRoot

View File

@ -20,6 +20,7 @@ namespace RazorPagesWebSite
options.AuthorizeFolder("/Pages/Admin");
options.AllowAnonymousToPage("/Pages/Admin/Login");
options.AddPageRoute("/HelloWorldWithRoute", "Different-Route/{text}");
options.AddPageRoute("/Pages/NotTheRoot", string.Empty);
})
.WithRazorPagesAtContentRoot();
}