From 078ecab666ebed1e47e654055edf28d839225d81 Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 3 Sep 2026 10:35:52 +0800 Subject: [PATCH] fix: Fix the issue where login fails when the returnUrl is empty. --- .../Pages/Account/ChangePassword.cshtml.cs | 4 ++-- .../Pages/Account/EmailConfirm.cshtml.cs | 2 +- .../Pages/Account/EmailConfirmConfirmation.cshtml.cs | 4 ++-- .../Pages/Account/LinkLogged.cshtml.cs | 10 +++++----- .../Pages/Account/Login.cshtml.cs | 12 ++++++------ .../Pages/Account/Register.cshtml.cs | 2 +- .../Pages/Account/SendCode.cshtml.cs | 2 +- .../Pages/Account/SendEmailConfirm.cshtml.cs | 2 +- .../Pages/Account/VerifyAuthenticatorCode.cshtml.cs | 4 ++-- .../Pages/Account/VerifyCode.cshtml.cs | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/ChangePassword.cshtml.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/ChangePassword.cshtml.cs index 5cf33d6c7..8be13debe 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/ChangePassword.cshtml.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/ChangePassword.cshtml.cs @@ -56,7 +56,7 @@ public class ChangePasswordModel : AccountPageModel [HiddenInput] [BindProperty(SupportsGet = true)] - public string ReturnUrl { get; set; } = default!; + public string? ReturnUrl { get; set; } [HiddenInput] [BindProperty(SupportsGet = true)] @@ -135,7 +135,7 @@ public class ChangePasswordModel : AccountPageModel UserName = user.UserName }); await IdentityDynamicClaimsPrincipalContributorCache.ClearAsync(user.Id, user.TenantId); - return await RedirectSafelyAsync(ReturnUrl, ReturnUrlHash); + return await RedirectSafelyAsync(ReturnUrl!, ReturnUrlHash); } catch (Exception ex) { diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/EmailConfirm.cshtml.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/EmailConfirm.cshtml.cs index d395c3c73..949fb3022 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/EmailConfirm.cshtml.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/EmailConfirm.cshtml.cs @@ -24,7 +24,7 @@ namespace LINGYUN.Abp.Account.Web.Pages.Account [HiddenInput] [BindProperty(SupportsGet = true)] - public string ReturnUrl { get; set; } = default!; + public string? ReturnUrl { get; set; } [HiddenInput] [BindProperty(SupportsGet = true)] diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/EmailConfirmConfirmation.cshtml.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/EmailConfirmConfirmation.cshtml.cs index 83cf2e111..ce8d46f64 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/EmailConfirmConfirmation.cshtml.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/EmailConfirmConfirmation.cshtml.cs @@ -9,14 +9,14 @@ namespace LINGYUN.Abp.Account.Web.Pages.Account; public class EmailConfirmConfirmationModel : AccountPageModel { [BindProperty(SupportsGet = true)] - public string ReturnUrl { get; set; } = default!; + public string? ReturnUrl { get; set; } [BindProperty(SupportsGet = true)] public string? ReturnUrlHash { get; set; } public async virtual Task OnGetAsync() { - ReturnUrl = await GetRedirectUrlAsync(ReturnUrl, ReturnUrlHash); + ReturnUrl = await GetRedirectUrlAsync(ReturnUrl!, ReturnUrlHash); return Page(); } diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/LinkLogged.cshtml.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/LinkLogged.cshtml.cs index dd85fa403..a31b6e45e 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/LinkLogged.cshtml.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/LinkLogged.cshtml.cs @@ -14,7 +14,7 @@ namespace LINGYUN.Abp.Account.Web.Pages.Account; public class LinkLoggedModel : AccountPageModel { [BindProperty(SupportsGet = true)] - public string ReturnUrl { get; set; } = default!; + public string? ReturnUrl { get; set; } [BindProperty(SupportsGet = true)] public string? ReturnUrlHash { get; set; } @@ -56,7 +56,7 @@ public class LinkLoggedModel : AccountPageModel { if (LinkUserId == CurrentUser.Id && LinkTenantId == CurrentTenant.Id) { - return await RedirectSafelyAsync(ReturnUrl, ReturnUrlHash); + return await RedirectSafelyAsync(ReturnUrl!, ReturnUrlHash); } using (CurrentTenant.Change(LinkTenantId)) @@ -81,7 +81,7 @@ public class LinkLoggedModel : AccountPageModel await IdentityDynamicClaimsPrincipalContributorCache.ClearAsync(targetUser.Id, targetUser.TenantId); } - return await RedirectSafelyAsync(ReturnUrl, ReturnUrlHash); + return await RedirectSafelyAsync(ReturnUrl!, ReturnUrlHash); } } } @@ -90,9 +90,9 @@ public class LinkLoggedModel : AccountPageModel return Page(); } - public virtual Task GetReturnUrlAsync(string returnUrl, string? returnUrlHash = null) + public virtual Task GetReturnUrlAsync(string? returnUrl, string? returnUrlHash = null) { - return base.GetRedirectUrlAsync(returnUrl, returnUrlHash); + return base.GetRedirectUrlAsync(returnUrl!, returnUrlHash); } protected virtual Task RedirectToLoginPageAsync() diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Login.cshtml.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Login.cshtml.cs index 323780385..dd11cabcd 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Login.cshtml.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Login.cshtml.cs @@ -41,7 +41,7 @@ public class LoginModel : AccountPageModel { [HiddenInput] [BindProperty(SupportsGet = true)] - public string ReturnUrl { get; set; } = default!; + public string? ReturnUrl { get; set; } [HiddenInput] [BindProperty(SupportsGet = true)] @@ -217,7 +217,7 @@ public class LoginModel : AccountPageModel // Clear the dynamic claims cache. await IdentityDynamicClaimsPrincipalContributorCache.ClearAsync(user.Id, user.TenantId); - return await RedirectSafelyAsync(ReturnUrl, ReturnUrlHash); + return await RedirectSafelyAsync(ReturnUrl!, ReturnUrlHash); } public async virtual Task OnPostPhoneNumberLogin(string action) @@ -269,7 +269,7 @@ public class LoginModel : AccountPageModel // Clear the dynamic claims cache. await IdentityDynamicClaimsPrincipalContributorCache.ClearAsync(user.Id, user.TenantId); - return await RedirectSafelyAsync(ReturnUrl, ReturnUrlHash); + return await RedirectSafelyAsync(ReturnUrl!, ReturnUrlHash); } protected virtual void SetTenantCookies(Guid? tenantId = null) @@ -356,7 +356,7 @@ public class LoginModel : AccountPageModel // Clear the dynamic claims cache. await IdentityDynamicClaimsPrincipalContributorCache.ClearAsync(user.Id, user.TenantId); - return await RedirectSafelyAsync(ReturnUrl, ReturnUrlHash); + return await RedirectSafelyAsync(ReturnUrl!, ReturnUrlHash); } } @@ -669,9 +669,9 @@ public class LoginModel : AccountPageModel #region LinkUser - public async virtual Task GetWithoutLinkReturnUrlAsync(string returnUrl, string? returnUrlHash = null) + public async virtual Task GetWithoutLinkReturnUrlAsync(string? returnUrl, string? returnUrlHash = null) { - var redirectUrl = await base.GetRedirectUrlAsync(returnUrl, returnUrlHash); + var redirectUrl = await base.GetRedirectUrlAsync(returnUrl!, returnUrlHash); // 使用正则表达式移除 LinkUser 参数 redirectUrl = Regex.Replace(redirectUrl, @"[&?]LinkToken=[^&]*", ""); diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Register.cshtml.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Register.cshtml.cs index 070c01665..54bb0def2 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Register.cshtml.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/Register.cshtml.cs @@ -32,7 +32,7 @@ public class RegisterModel : AccountPageModel { [HiddenInput] [BindProperty(SupportsGet = true)] - public string ReturnUrl { get; set; } = default!; + public string? ReturnUrl { get; set; } [HiddenInput] [BindProperty(SupportsGet = true)] diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/SendCode.cshtml.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/SendCode.cshtml.cs index eb25accb6..ed32f0d43 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/SendCode.cshtml.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/SendCode.cshtml.cs @@ -20,7 +20,7 @@ namespace LINGYUN.Abp.Account.Web.Pages.Account [HiddenInput] [BindProperty(SupportsGet = true)] - public string ReturnUrl { get; set; } = default!; + public string? ReturnUrl { get; set; } [HiddenInput] [BindProperty(SupportsGet = true)] diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/SendEmailConfirm.cshtml.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/SendEmailConfirm.cshtml.cs index 5f575c290..b7cf2e3e7 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/SendEmailConfirm.cshtml.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/SendEmailConfirm.cshtml.cs @@ -14,7 +14,7 @@ namespace LINGYUN.Abp.Account.Web.Pages.Account [HiddenInput] [BindProperty(SupportsGet = true)] - public string ReturnUrl { get; set; } = default!; + public string? ReturnUrl { get; set; } [HiddenInput] [BindProperty(SupportsGet = true)] diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/VerifyAuthenticatorCode.cshtml.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/VerifyAuthenticatorCode.cshtml.cs index 8135ad8b1..fec3efc16 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/VerifyAuthenticatorCode.cshtml.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/VerifyAuthenticatorCode.cshtml.cs @@ -13,7 +13,7 @@ namespace LINGYUN.Abp.Account.Web.Pages.Account [HiddenInput] [BindProperty(SupportsGet = true)] - public string ReturnUrl { get; set; } = default!; + public string? ReturnUrl { get; set; } [HiddenInput] [BindProperty(SupportsGet = true)] @@ -37,7 +37,7 @@ namespace LINGYUN.Abp.Account.Web.Pages.Account var result = await SignInManager.TwoFactorAuthenticatorSignInAsync(Input.VerifyCode, RememberMe, RememberBrowser); if (result.Succeeded) { - return await RedirectSafelyAsync(ReturnUrl, ReturnUrlHash); + return await RedirectSafelyAsync(ReturnUrl!, ReturnUrlHash); } if (result.IsLockedOut) { diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/VerifyCode.cshtml.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/VerifyCode.cshtml.cs index cf9860ea1..93550927c 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/VerifyCode.cshtml.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Pages/Account/VerifyCode.cshtml.cs @@ -28,7 +28,7 @@ namespace LINGYUN.Abp.Account.Web.Pages.Account /// [HiddenInput] [BindProperty(SupportsGet = true)] - public string ReturnUrl { get; set; } = default!; + public string? ReturnUrl { get; set; } /// /// /// @@ -96,7 +96,7 @@ namespace LINGYUN.Abp.Account.Web.Pages.Account // Clear the dynamic claims cache. await IdentityDynamicClaimsPrincipalContributorCache.ClearAsync(user.Id, user.TenantId); - return await RedirectSafelyAsync(ReturnUrl, ReturnUrlHash); + return await RedirectSafelyAsync(ReturnUrl!, ReturnUrlHash); } if (result.IsLockedOut) {