在 Blazor 应用程序中登录时重定向错误
Wrong redirect when login in blazor application
我使用 ASP.NET Core 3.1 Blazor webassembly 应用程序(由 Visual Studio 2019 创建的默认应用程序)。
我连接了 ASP.NET 用户管理身份,添加了脚手架身份项目(登录、注册等)
当我单击 注册 时,应用程序正确重定向到
https://localhost:44349/Identity/Account/Register
但如果我单击 登录,应用程序将重定向到
https://localhost:44349/Account/Login
这是错误的(我预计 https://localhost:44349/Identity/Account/Login
)
LoginDisplay.razor:
<AuthorizeView>
<Authorized>
<a href="authentication/profile">Hello, @context.User.Identity.Name!</a>
<button class="nav-link btn btn-link" @onclick="BeginSignOut">Log out</button>
</Authorized>
<NotAuthorized>
<a href="authentication/register">Register</a>
<a href="authentication/login">Log in</a>
</NotAuthorized>
</AuthorizeView>
我错过了什么?
替换
services.AddIdentity<ApplicationUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
和
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
我解决了这个问题
我使用 ASP.NET Core 3.1 Blazor webassembly 应用程序(由 Visual Studio 2019 创建的默认应用程序)。
我连接了 ASP.NET 用户管理身份,添加了脚手架身份项目(登录、注册等)
当我单击 注册 时,应用程序正确重定向到
https://localhost:44349/Identity/Account/Register
但如果我单击 登录,应用程序将重定向到
https://localhost:44349/Account/Login
这是错误的(我预计 https://localhost:44349/Identity/Account/Login
)
LoginDisplay.razor:
<AuthorizeView>
<Authorized>
<a href="authentication/profile">Hello, @context.User.Identity.Name!</a>
<button class="nav-link btn btn-link" @onclick="BeginSignOut">Log out</button>
</Authorized>
<NotAuthorized>
<a href="authentication/register">Register</a>
<a href="authentication/login">Log in</a>
</NotAuthorized>
</AuthorizeView>
我错过了什么?
替换
services.AddIdentity<ApplicationUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
和
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
我解决了这个问题