aspnetcore 2中的Razor页面默认页面 [英] Razor Pages Default Page in aspnetcore 2
问题描述
默认情况下,Razor Page应用进入首页/索引
By default a Razor Page app goes to Home/Index
是否可以将其更改为Home/App?
Is there a way to change this to Home/App?
这在MVC中非常容易,但是Razor页面使用不同的路由设置,因此MVC路由不适用.
This is quite easy in MVC, but Razor pages using a different routing setup and thus MVC routing does not apply.
我认为它将在某处的期权中,但我没有看到它:
I would think it would be in options somewhere, but I don't see it:
services.AddMvc()
.AddRazorPagesOptions(options =>
{
options.Conventions.AuthorizeFolder("/Account/Manage");
options.Conventions.AuthorizePage("/Account/Logout");
options. ??SetDefaultPage??
});
我已经尝试过了:
options.Conventions.AddPageRoute("/App", "");
但是现在找到了两个默认路由,并生成了一个错误:
But now two default routes are found and an error is generated:
AmbiguousActionException:多个动作匹配.以下动作与路线数据匹配,并且满足所有约束条件:
AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:
页面:/App
页面:/索引
可以通过从项目中删除Pages/Index.cshtml来解决此错误,但我也希望保留该页面.
It's possible to resolve this error by removing Pages/Index.cshtml from the project, but I wanted to keep that page as well.
推荐答案
非常确定这是不可能的.文档说,运行时控制搜索Index
作为默认设置.我找不到当前版本中发生的情况,但IndexFileName
是新内部
Pretty sure it isn't possible. The docs say the runtime controls the search for Index
as the default. I couldn't find where that happens in the current release, but IndexFileName
is a static
in the new internal PageRouteModelFactory
class added to the upcoming release:
private static readonly string IndexFileName = "Index" + RazorViewEngine.ViewExtension;
It doesn't seem like it would be difficult to just add a config property to RazorPagesOptions
, though. The ASP.NET guys are pretty responsive, I'd open a request as a GitHub issue and hope for the best.
这篇关于aspnetcore 2中的Razor页面默认页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!