到同一剃须刀页面的多条路线
Multiple routes to the same razor page
背景
我的 Asp.Net Core 3.1 网站上有一个名为 SignupAndApply 的剃刀页面。它实际上是注册身份页面的复制和粘贴,但是:
- 有一些额外的字段
- 允许将可选的 applyid 作为路由的一部分传递
- 如果我将 applyId 作为路由的一部分传递,我会对页面进行一些标签更改并将用户重定向到其他地方
我想为这个页面创建两个路由:
/identity/account/signupandapply/{applyId?} 'when the user is applying and signing up
/identity/account/signup 'when the user is just signing up
我已将以下内容添加到页面顶部:
@page "{applyId?}"
并将 applyId 设置为 OnGetAsync 方法的可选参数:
public async Task OnGetAsync(string returnUrl = null, Guid? applyId = null)
问题
带有 applyId 的路由有效,但 /identity/account/signup 路由无效。
我试过将它添加到我的启动程序中:
services.AddMvc()
.AddRazorPagesOptions(options => options.Conventions
.AddPageRoute("/identity/account/signupandapply", "/identity/account/signup")
);
如果我去其中一个就可以了
/identity/account/signupandapply/<fooapplyid>
/identity/account/signupandapply
但不是这个
/identity/account/signup
知道我做错了什么应该添加一条简单的替代路线吗?
页面(/identity/account/signupandapply
)在区域Identity
,所以你需要使用AddAreaPageRoute
而不是AddAreaPage
:
services.AddRazorPages().AddRazorPagesOptions(options =>
{
options.Conventions.AddAreaPageRoute("Identity",
"/account/signupandapply", "identity/account/signup");
}); ;
背景
我的 Asp.Net Core 3.1 网站上有一个名为 SignupAndApply 的剃刀页面。它实际上是注册身份页面的复制和粘贴,但是:
- 有一些额外的字段
- 允许将可选的 applyid 作为路由的一部分传递
- 如果我将 applyId 作为路由的一部分传递,我会对页面进行一些标签更改并将用户重定向到其他地方
我想为这个页面创建两个路由:
/identity/account/signupandapply/{applyId?} 'when the user is applying and signing up
/identity/account/signup 'when the user is just signing up
我已将以下内容添加到页面顶部:
@page "{applyId?}"
并将 applyId 设置为 OnGetAsync 方法的可选参数:
public async Task OnGetAsync(string returnUrl = null, Guid? applyId = null)
问题
带有 applyId 的路由有效,但 /identity/account/signup 路由无效。
我试过将它添加到我的启动程序中:
services.AddMvc()
.AddRazorPagesOptions(options => options.Conventions
.AddPageRoute("/identity/account/signupandapply", "/identity/account/signup")
);
如果我去其中一个就可以了
/identity/account/signupandapply/<fooapplyid>
/identity/account/signupandapply
但不是这个
/identity/account/signup
知道我做错了什么应该添加一条简单的替代路线吗?
页面(/identity/account/signupandapply
)在区域Identity
,所以你需要使用AddAreaPageRoute
而不是AddAreaPage
:
services.AddRazorPages().AddRazorPagesOptions(options =>
{
options.Conventions.AddAreaPageRoute("Identity",
"/account/signupandapply", "identity/account/signup");
}); ;