背景
我在Asp.Net Core 3.1网站上有一个剃须刀页面,名为SignupAndApply。它实际上是注册人身份页面的复制和粘贴,但:
我要为此页面创建两条路线:
/identity/account/signupandapply/{applyId?} 'when the user is applying and signing up
/identity/account/signup 'when the user is just signing up
我在页面顶部添加了以下内容:
@page "{applyId?}"
并在OnGetAsync方法上将applyId设置为可选参数:
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
有什么想法我在做错什么,应该添加一条简单的替代路线吗?
答案 0 :(得分:1)
页面(/identity/account/signupandapply
)位于区域Identity
中,因此您需要使用AddAreaPageRoute
而不是AddAreaPage
:
services.AddRazorPages().AddRazorPagesOptions(options =>
{
options.Conventions.AddAreaPageRoute("Identity",
"/account/signupandapply", "identity/account/signup");
}); ;