Allow AddPageRoute to route to pages root. (#6412)
* Allow AddPageRoute to route to pages root. Fixes #6338
This commit is contained in:
parent
f824704741
commit
c89f0a1e43
|
|
@ -193,9 +193,9 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(pageName));
|
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 =>
|
options.Conventions.Add(new PageConvention(pageName, model =>
|
||||||
|
|
|
||||||
|
|
@ -1037,6 +1037,19 @@ Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary`1[AspNetCore._InjectedP
|
||||||
Assert.StartsWith(expected, response.Trim());
|
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)
|
private async Task AddAntiforgeryHeaders(HttpRequestMessage request)
|
||||||
{
|
{
|
||||||
var getResponse = await Client.GetAsync(request.RequestUri);
|
var getResponse = await Client.GetAsync(request.RequestUri);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
@page
|
||||||
|
Hello from NotTheRoot
|
||||||
|
|
@ -20,6 +20,7 @@ namespace RazorPagesWebSite
|
||||||
options.AuthorizeFolder("/Pages/Admin");
|
options.AuthorizeFolder("/Pages/Admin");
|
||||||
options.AllowAnonymousToPage("/Pages/Admin/Login");
|
options.AllowAnonymousToPage("/Pages/Admin/Login");
|
||||||
options.AddPageRoute("/HelloWorldWithRoute", "Different-Route/{text}");
|
options.AddPageRoute("/HelloWorldWithRoute", "Different-Route/{text}");
|
||||||
|
options.AddPageRoute("/Pages/NotTheRoot", string.Empty);
|
||||||
})
|
})
|
||||||
.WithRazorPagesAtContentRoot();
|
.WithRazorPagesAtContentRoot();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue