Nei*_*eil 4 c# asp.net-core-mvc .net-core asp.net-core razor-pages
背景
我的 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
Run Code Online (Sandbox Code Playgroud)
我已将以下内容添加到页面顶部:
@page "{applyId?}"
Run Code Online (Sandbox Code Playgroud)
并将 applyId 设置为 OnGetAsync 方法上的可选参数:
@page "{applyId?}"
Run Code Online (Sandbox Code Playgroud)
问题
带有 applyId 的路由有效,但 /identity/account/signup 路由无效。
我尝试将其添加到我的启动中:
public async Task OnGetAsync(string returnUrl = null, Guid? applyId = null)
Run Code Online (Sandbox Code Playgroud)
如果我去其中之一就可以了
/identity/account/signupandapply/<fooapplyid>
/identity/account/signupandapply
Run Code Online (Sandbox Code Playgroud)
但不是这个
/identity/account/signup
Run Code Online (Sandbox Code Playgroud)
有什么想法我做错了什么应该添加一个简单的替代路线吗?
page( /identity/account/signupandapply) 位于区域中Identity,因此您需要使用AddAreaPageRoute而不是AddAreaPage:
services.AddRazorPages().AddRazorPagesOptions(options =>
{
options.Conventions.AddAreaPageRoute("Identity",
"/account/signupandapply", "identity/account/signup");
}); ;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5459 次 |
| 最近记录: |