到同一剃刀页面的多条路线 [英] Multiple routes to the same razor page

查看:55
本文介绍了到同一剃刀页面的多条路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我在Asp.Net Core 3.1网站上有一个剃须刀页面,名为SignupAndApply.它实际上是注册人身份页面的复制和粘贴,但:

I've got a razor page in my Asp.Net Core 3.1 website called SignupAndApply. It's effectively a copy and paste of the register identity page but:

  • 还有一些其他字段
  • 允许将可选的applyid作为路线的一部分传递
  • 如果我在路由中传递了applyId,则会对页面进行几次标签更改,并将用户重定向到其他地方

我要为此页面创建两条路线:

I want to create two routes for this page:

/identity/account/signupandapply/{applyId?} 'when the user is applying and signing up
/identity/account/signup 'when the user is just signing up

我在页面顶部添加了以下内容:

I've added the following to the top of the page:

@page "{applyId?}"

并在OnGetAsync方法上将applyId设置为可选参数:

And set the applyId as an optional parameter on the OnGetAsync method:

public async Task OnGetAsync(string returnUrl = null, Guid? applyId = null)

问题

带有applyId的路由有效,但/identity/account/signup路由无效.

The route with the applyId is working but the /identity/account/signup route isn't.

我尝试将其添加到我的启动中:

I've tried adding this to my startup:

services.AddMvc()
        .AddRazorPagesOptions(options => options.Conventions
                             .AddPageRoute("/identity/account/signupandapply", "/identity/account/signup")
                             );

如果我去其中之一就行了

It works if I go to one of these

/identity/account/signupandapply/<fooapplyid>
/identity/account/signupandapply

但不是这个

/identity/account/signup

有什么想法我在做错什么,应该添加一条简单的替代路线吗?

Any ideas what I'm doing wrong for what should be adding a simple alternative route?

推荐答案

页面(/identity/account/signupandapply )位于区域 Identity 中,因此您需要使用 AddAreaPageRoute 代替 AddAreaPage :

The page(/identity/account/signupandapply) is in area Identity ,so you need to use AddAreaPageRoute instead of AddAreaPage :

services.AddRazorPages().AddRazorPagesOptions(options =>
{

    options.Conventions.AddAreaPageRoute("Identity",
           "/account/signupandapply", "identity/account/signup");

    }); ;

这篇关于到同一剃刀页面的多条路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆