Open Closed

Pages/Account/Login OnPostAsync(string action) override #8849


User avatar
0
LiSong created
  • ABP Framework version: v9.X.X
  • UI Type: MVC
  • Database System: EF Core (SQL Server, Oracle, MySQL, PostgreSQL, etc..) / MongoDB
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

I need to modify the Task<IActionResult> OnPostAsync(string action) function in Pages/Account/Login. Therefore, I created a new class and copied the code into a new subclass. The code is as follows:

Without making any changes, an error occurs when running the code. However, if I remove this function, it runs normally.

I have attached all the relevant code. I noticed that the value of the action parameter being passed is null, this should be root cause

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Owl.reCAPTCHA;
using Volo.Abp;
using Volo.Abp.Account;
using Volo.Abp.Account.ExternalProviders;
using Volo.Abp.Account.Public.Web;
using Volo.Abp.Account.Public.Web.Pages.Account;
using Volo.Abp.Account.Public.Web.Security.Recaptcha;
using Volo.Abp.Account.Security.Recaptcha;
using Volo.Abp.Account.Settings;
using Volo.Abp.Auditing;
using Volo.Abp.Identity;
using Volo.Abp.Identity.AspNetCore;
using Volo.Abp.Identity.Settings;
using Volo.Abp.Reflection;
using Volo.Abp.Security.Claims;
using Volo.Abp.Settings;
using Volo.Abp.Uow;
using Volo.Abp.Users;
using Volo.Abp.Validation;
using IdentityUser = Volo.Abp.Identity.IdentityUser;

namespace Tapp.Web.Pages.Account;

[DisableAuditing]
public class TappLoginModel : LoginModel
{

    public TappLoginModel(
        IAuthenticationSchemeProvider schemeProvider,
        IOptions<AbpAccountOptions> accountOptions,
        IAbpRecaptchaValidatorFactory recaptchaValidatorFactory,
        IAccountExternalProviderAppService accountExternalProviderAppService,
        ICurrentPrincipalAccessor currentPrincipalAccessor,
        IOptions<IdentityOptions> identityOptions,
        IOptionsSnapshot<reCAPTCHAOptions> reCaptchaOptions) : base(
            schemeProvider,
            accountOptions,
            recaptchaValidatorFactory,
            accountExternalProviderAppService,
            currentPrincipalAccessor,
            identityOptions,
            reCaptchaOptions)
    {

    }


    [UnitOfWork] //TODO: Will be removed when we implement action filter
    public override async Task<IActionResult> OnPostAsync(string action)
    {
        string action2 = action;
        try
        {
            await ReCaptchaVerification();
        }
        catch (UserFriendlyException e)
        {
            if (e is ScoreBelowThresholdException)
            {
                var onScoreBelowThresholdResult = OnRecaptchaScoreBelowThreshold();
                if (onScoreBelowThresholdResult != null)
                {
                    return await onScoreBelowThresholdResult;
                }
            }

            Alerts.Danger(GetLocalizeExceptionMessage(e));
            return Page();
        }
        var validationResult = new AbpValidationResult();

        //AddErrors(validationResult, ModelState);
        
        if (ModelState.IsValid)
        {
            throw new AbpValidationException(
                "ModelState is not valid! See ValidationErrors for details.",
                validationResult.Errors
            );
        }

        foreach (var state in ModelState)
        {
            foreach (var error in state.Value.Errors)
            {
                validationResult.Errors.Add(new ValidationResult(error.ErrorMessage, new[] { state.Key }));
            }
        }

        if (validationResult.Errors.Any())
        {
            throw new AbpValidationException(
                "ModelState is not valid! See ValidationErrors for details.",
                validationResult.Errors
            );
        }
        //I commented it out for debugging purpose
        //ValidateModel();



@page
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.Extensions.Options
@using Owl.reCAPTCHA
@using Volo.Abp.Account.Localization
@using Volo.Abp.Account.Public.Web.Pages.Account;
@using Volo.Abp.Account.Public.Web.Security.Recaptcha
@using Volo.Abp.Account.Settings
@using Volo.Abp.Identity;
@using Volo.Abp.Settings
@model Tapp.Web.Pages.Account.TappLoginModel

@inject IHtmlLocalizer<AccountResource> L
@inject Volo.Abp.AspNetCore.Mvc.UI.Layout.IPageLayout PageLayout
@inject ISettingProvider SettingProvider
@{
    PageLayout.Content.Title = L["Login"].Value;
    var reCaptchaVersion = await SettingProvider.GetAsync<int>(AccountSettingNames.Captcha.Version);
    if (Model.UseCaptcha)
    {
        await Model.ReCaptchaOptions.SetAsync(reCaptchaVersion == 3 ? reCAPTCHAConsts.V3 : reCAPTCHAConsts.V2);
    }

}

@section scripts
    {
    <abp-script-bundle name="@typeof(LoginModel).FullName">
        <abp-script src="/Pages/Account/Login.js" />
    </abp-script-bundle>

    @if (Model.UseCaptcha)
    {
        if (reCaptchaVersion == 3)
        {
            <recaptcha-script-v3 />
            <recaptcha-script-v3-js action="login" execute="false" />
        }
        else
        {
            <recaptcha-script-v2 />
        }
    }
}

@if (Model.IsLinkLogin)
{
    <abp-alert alert-type="Warning">
        @L["LinkAccountWarning", Url.PageLink()]
    </abp-alert>
}

@if (Model.BackToExternalLogins)
{
    <div class="d-grid gap-2">
        <a class="mb-3 btn btn-primary btn-block" href="@Url.Page("./ExternalLogins")">@L["Back"]</a>
    </div>
}
<div class="account-module-form">

    @if (Model.IsSelfRegistrationEnabled)
    {
        <h5 class="mb-2">@L["NotAMemberYet"] <a class="text-decoration-none" href="@Url.Page("./Register", new {returnUrl = Model.ReturnUrl, returnUrlHash = Model.ReturnUrlHash})">@L["Register"]</a></h5>
    }

    @if (Model.EnableLocalLogin)
    {
        <form method="post" id="loginForm">
            @if (Model.UseCaptcha)
            {
                <input class="mb-3" data-captcha="true" type="hidden" name="@RecaptchaValidatorBase.RecaptchaResponseKey" id="@RecaptchaValidatorBase.RecaptchaResponseKey"/>
            }
            <div>
                <div class="form-floating mb-2">
                    <input asp-for="LoginInput.UserNameOrEmailAddress" type="text" class="form-control" placeholder="name@example.com">
                    @Html.LabelFor(m => m.LoginInput.UserNameOrEmailAddress)
                    <span asp-validation-for="LoginInput.UserNameOrEmailAddress"/>
                </div>

                <div class="form-floating mb-2">
                    <input asp-for="LoginInput.Password" id="password-input" type="password" class="form-control" placeholder="Password">
                    @Html.LabelFor(m => m.LoginInput.Password)
                    <i id="PasswordVisibilityButton" class="bi bi-eye-slash show-pass-icon" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true" aria-label="@L["ShowPassword"]" data-bs-original-title="@L["ShowPassword"]"></i>
                    <i id="capslockicon" class="bi bi-capslock caps-lock-icon" style="display: none;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true" aria-label="<i class='bi bi-exclamation-circle'></i> @L["CapsLockOn"]!" data-bs-original-title="<i class='bi bi-exclamation-circle'></i> @L["CapsLockOn"]!"></i>
                    <span asp-validation-for="LoginInput.Password"/>
                </div>
            </div>
            <abp-row>
                <abp-column>
                    <div class="form-switch ps-2">
                        <abp-input asp-for="LoginInput.RememberMe" class="mb-4"/>
                    </div>
                </abp-column>
                <abp-column class="text-end">
                    <a href="@Url.Page("./ForgotPassword", new {returnUrl = Model.ReturnUrl, returnUrlHash = Model.ReturnUrlHash})">@L["ForgotPassword"]</a>
                </abp-column>
            </abp-row>

            @if (reCaptchaVersion == 2)
            {
                <script>
                    recaptchaCallback = function (token) {
                        $('form button[type=submit]').removeAttr("disabled");
                        $('#@RecaptchaValidatorBase.RecaptchaResponseKey').val(token)
                    };
                </script>
                <div class="mb-3">
                    <recaptcha-div-v2 callback="recaptchaCallback"/>
                </div>
            }

            <div class="d-grid gap-2">
                <abp-button button-type="Primary" type="submit" class="mb-3" name="Action" value="Login" disabled="true">
                    <i class="bi bi-box-arrow-in-right me-1"></i>
                    @L["Login"]
                </abp-button>
            </div>

            @if (Model.ShowCancelButton)
            {
                <div class="d-grid gap-2">
                    <abp-button button-type="Secondary" type="submit" formnovalidate="formnovalidate" class="mb-3" name="Action" value="Cancel">@L["Cancel"]</abp-button>
                </div>
            }
        </form>
    }

    @if (Model.VisibleExternalProviders.Any())
    {
        if(Model.EnableLocalLogin)
        {
            <hr/>
            @L["OrSignInWith"]
            <br/>
        }
        else
        {
            @L["SignInWithOneOfTheFollowingProviders"]
        }

        <form asp-page="./Login" asp-page-handler="ExternalLogin"
              asp-route-returnUrl="@Model.ReturnUrl"
              asp-route-returnUrlHash="@Model.ReturnUrlHash"
              asp-route-linkTenantId="@Model.LinkTenantId"
              asp-route-linkUserId="@Model.LinkUserId"
              asp-route-linkToken="@Model.LinkToken"
              method="post">
            @foreach (var provider in Model.VisibleExternalProviders)
            {
                <button type="submit"
                        class="mt-2 me-2 btn btn-outline-primary btn-sm"
                        name="provider"
                        value="@provider.AuthenticationScheme"
                        data-busy-text="@L["ProcessingWithThreeDot"]">
                    @if (provider.Icon != null)
                    {
                        <i class="@provider.Icon"></i>
                    }
                    <span>@provider.DisplayName</span>
                </button>
            }
        </form>
    }
</div>
An unhandled exception occurred while processing the request.
AbpValidationException: ModelState is not valid! See ValidationErrors for details.
Tapp.Web.Pages.Account.TappLoginModel.OnPostAsync(string action) in Login.cshtml.cs, line 105

Stack Query Cookies Headers Routing
AbpValidationException: ModelState is not valid! See ValidationErrors for details.
Tapp.Web.Pages.Account.TappLoginModel.OnPostAsync(string action) in Login.cshtml.cs
+
            throw new AbpValidationException(
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory+GenericTaskHandlerMethod.Convert<T>(object taskAsObject)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory+GenericTaskHandlerMethod.Execute(object receiver, object[] arguments)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ExceptionContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
Volo.Abp.AspNetCore.Serilog.AbpSerilogMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext()
Volo.Abp.AspNetCore.Auditing.AbpAuditingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
Volo.Abp.AspNetCore.Auditing.AbpAuditingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext()
Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Volo.Abp.AspNetCore.Security.Claims.AbpDynamicClaimsMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext()
Volo.Abp.AspNetCore.Uow.AbpUnitOfWorkMiddleware.InvokeAsync(HttpContex

14 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hi,

    If you want to override only LoginModel you can do it as below:

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(LoginModel))]
    [DisableAuditing]
    public class TappLoginModel : LoginModel
    {
    
        public TappLoginModel(
            IAuthenticationSchemeProvider schemeProvider,
            IOptions<AbpAccountOptions> accountOptions,
            IAbpRecaptchaValidatorFactory recaptchaValidatorFactory,
            IAccountExternalProviderAppService accountExternalProviderAppService,
            ICurrentPrincipalAccessor currentPrincipalAccessor,
            IOptions<IdentityOptions> identityOptions,
            IOptionsSnapshot<reCAPTCHAOptions> reCaptchaOptions) : base(
            schemeProvider,
            accountOptions,
            recaptchaValidatorFactory,
            accountExternalProviderAppService,
            currentPrincipalAccessor,
            identityOptions,
            reCaptchaOptions)
        {
    
        }
    
        public override Task<IActionResult> OnGetAsync()
        {
            return base.OnGetAsync();
        }
    
    
        [UnitOfWork] //TODO: Will be removed when we implement action filter
        public virtual async Task<IActionResult> OnPostAsync(string action)
        {
            try
            {
                await ReCaptchaVerification();
            }
            catch (UserFriendlyException e)
            {
                if (e is ScoreBelowThresholdException)
                {
                    var onScoreBelowThresholdResult = OnRecaptchaScoreBelowThreshold();
                    if (onScoreBelowThresholdResult != null)
                    {
                        return await onScoreBelowThresholdResult;
                    }
                }
    
                Alerts.Danger(GetLocalizeExceptionMessage(e));
                return Page();
            }
    
            ValidateModel();
    
            await IdentityOptions.SetAsync();
    
            var localLoginResult = await CheckLocalLoginAsync();
            if (localLoginResult != null)
            {
                return localLoginResult;
            }
    
            IsSelfRegistrationEnabled = await SettingProvider.IsTrueAsync(AccountSettingNames.IsSelfRegistrationEnabled);
    
            await ReplaceEmailToUsernameOfInputIfNeeds();
    
            IsLinkLogin = await VerifyLinkTokenAsync();
    
            var result = await SignInManager.PasswordSignInAsync(
                LoginInput.UserNameOrEmailAddress,
                LoginInput.Password,
                LoginInput.RememberMe,
                true
            );
    
            await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
            {
                Identity = IdentitySecurityLogIdentityConsts.Identity,
                Action = result.ToIdentitySecurityLogAction(),
                UserName = LoginInput.UserNameOrEmailAddress
            });
    
            if (result.RequiresTwoFactor)
            {
                return RedirectToPage("./SendSecurityCode", new {
                    returnUrl = ReturnUrl,
                    returnUrlHash = ReturnUrlHash,
                    rememberMe = LoginInput.RememberMe,
                    linkUserId = LinkUserId,
                    linkTenantId = LinkTenantId,
                    linkToken = LinkToken
                });
            }
    
    
            if (result.IsLockedOut)
            {
                var lockedUser = await GetIdentityUser(LoginInput.UserNameOrEmailAddress);
                await StoreLockedUser(lockedUser);
                return RedirectToPage("./LockedOut", new {
                    returnUrl = ReturnUrl,
                    returnUrlHash = ReturnUrlHash
                });
            }
    
            if (result.IsNotAllowed)
            {
                var notAllowedUser = await GetIdentityUser(LoginInput.UserNameOrEmailAddress);
    
                if (!await UserManager.CheckPasswordAsync(notAllowedUser, LoginInput.Password))
                {
                    Alerts.Danger(L["InvalidUserNameOrPassword"]);
                    return Page();
                }
    
                if (notAllowedUser.ShouldChangePasswordOnNextLogin || await UserManager.ShouldPeriodicallyChangePasswordAsync(notAllowedUser))
                {
                    await StoreChangePasswordUser(notAllowedUser);
                    return RedirectToPage("./ChangePassword", new {
                        returnUrl = ReturnUrl,
                        returnUrlHash = ReturnUrlHash,
                        RememberMe = LoginInput.RememberMe
                    });
                }
    
                if (notAllowedUser.IsActive)
                {
                    await StoreConfirmUser(notAllowedUser);
                    return RedirectToPage("./ConfirmUser", new {
                        returnUrl = ReturnUrl,
                        returnUrlHash = ReturnUrlHash
                    });
                }
    
                Alerts.Danger(L["LoginIsNotAllowed"]);
                return Page();
            }
    
            if (!result.Succeeded)
            {
                Alerts.Danger(L["InvalidUserNameOrPassword"]);
                return Page();
            }
    
            var user = await GetIdentityUser(LoginInput.UserNameOrEmailAddress);
    
            if (IsLinkLogin)
            {
                using (CurrentPrincipalAccessor.Change(await SignInManager.CreateUserPrincipalAsync(user)))
                {
                    await IdentityLinkUserAppService.LinkAsync(new LinkUserInput
                    {
                        UserId = LinkUserId.Value,
                        TenantId = LinkTenantId,
                        Token = LinkToken
                    });
    
                    await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
                    {
                        Identity = IdentitySecurityLogIdentityConsts.Identity,
                        Action = IdentityProSecurityLogActionConsts.LinkUser,
                        UserName = user.UserName,
                        ExtraProperties =
                            {
                                { IdentityProSecurityLogActionConsts.LinkTargetTenantId, LinkTenantId },
                                { IdentityProSecurityLogActionConsts.LinkTargetUserId, LinkUserId }
                            }
                    });
    
                    using (CurrentTenant.Change(LinkTenantId))
                    {
                        var targetUser = await UserManager.GetByIdAsync(LinkUserId.Value);
                        using (CurrentPrincipalAccessor.Change(await SignInManager.CreateUserPrincipalAsync(targetUser)))
                        {
                            await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
                            {
                                Identity = IdentitySecurityLogIdentityConsts.Identity,
                                Action = IdentityProSecurityLogActionConsts.LinkUser,
                                UserName = targetUser.UserName,
                                ExtraProperties =
                                    {
                                        { IdentityProSecurityLogActionConsts.LinkTargetTenantId, targetUser.TenantId },
                                        { IdentityProSecurityLogActionConsts.LinkTargetUserId, targetUser.Id }
                                    }
                            });
                        }
                    }
    
                    return RedirectToPage("./LinkLogged", new {
                        returnUrl = ReturnUrl,
                        returnUrlHash = ReturnUrlHash,
                        targetLinkUserId = LinkUserId,
                        targetLinkTenantId = LinkTenantId
                    });
                }
            }
    
            // Clear the dynamic claims cache.
            await IdentityDynamicClaimsPrincipalContributorCache.ClearAsync(user.Id, user.TenantId);
    
            return await RedirectSafelyAsync(ReturnUrl, ReturnUrlHash);
        }
    }
    
    
  • User Avatar
    0
    LiSong created

    I got this error page:

    An unhandled exception occurred while processing the request. ComponentNotRegisteredException: The requested service 'Tapp.Web.Pages.Account.TappLoginModel' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.

    See https://autofac.rtfd.io/help/service-not-registered for more info. Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable<Parameter> parameters)

    Stack Query Cookies Headers Routing ComponentNotRegisteredException: The requested service 'Tapp.Web.Pages.Account.TappLoginModel' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency. See https://autofac.rtfd.io/help/service-not-registered for more info. Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable<Parameter> parameters) Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType, IEnumerable<Parameter> parameters) Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType) Autofac.Extensions.DependencyInjection.AutofacServiceProvider.GetRequiredService(Type serviceType) Volo.Abp.AspNetCore.Mvc.UI.RazorPages.ServiceBasedPageModelActivatorProvider+<>c__DisplayClass0_0.<CreateActivator>b__0(PageContext context) Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DefaultPageModelFactoryProvider+<>c__DisplayClass3_0.<CreateModelFactory>b__0(PageContext pageContext) Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.CreateInstance() Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync() Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ExceptionContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResourceFilter() Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker) Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger) Volo.Abp.AspNetCore.Serilog.AbpSerilogMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext() Volo.Abp.AspNetCore.Auditing.AbpAuditingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Volo.Abp.AspNetCore.Auditing.AbpAuditingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext() Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) Volo.Abp.AspNetCore.Security.Claims.AbpDynamicClaimsMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext() Volo.Abp.AspNetCore.Uow.AbpUnitOfWorkMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext() Volo.Abp.AspNetCore.ExceptionHandling.AbpExceptionHandlingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Volo.Abp.AspNetCore.ExceptionHandling.AbpExceptionHandlingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext() Volo.Abp.AspNetCore.MultiTenancy.MultiTenancyMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext() Microsoft.AspNetCore.Builder.ApplicationBuilderAbpOpenIddictMiddlewareExtension+<>c__DisplayClass0_0+<<UseAbpOpenIddictValidation>b__0>d.MoveNext() Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) Volo.Abp.AspNetCore.Security.AbpSecurityHeadersMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext() Volo.Abp.Studio.Client.AspNetCore.AbpStudioMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Volo.Abp.Studio.Client.AspNetCore.AbpStudioMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Volo.Abp.Studio.Client.AspNetCore.AbpStudioMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext() Volo.Abp.AspNetCore.Tracing.AbpCorrelationIdMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext() Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.RequestLocalization.AbpRequestLocalizationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext() Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

    Show raw exception details

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Interesting, actually you shouldn't get such an error, but could you try as follows? If not, can you send me the code of TappLoginModel?

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(LoginModel))]
    [DisableAuditing]
    public class TappLoginModel : LoginModel, ITransientDependency
    {
        //...
    }
    
  • User Avatar
    0
    LiSong created

    same error using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Diagnostics; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Owl.reCAPTCHA; using Volo.Abp; using Volo.Abp.Account; using Volo.Abp.Account.ExternalProviders; using Volo.Abp.Account.Public.Web; using Volo.Abp.Account.Public.Web.Pages.Account; using Volo.Abp.Account.Public.Web.Security.Recaptcha; using Volo.Abp.Account.Security.Recaptcha; using Volo.Abp.Account.Settings; using Volo.Abp.Auditing; using Volo.Abp.DependencyInjection; using Volo.Abp.Identity; using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Identity.Settings; using Volo.Abp.Reflection; using Volo.Abp.Security.Claims; using Volo.Abp.Settings; using Volo.Abp.Uow; using Volo.Abp.Users; using Volo.Abp.Validation; using IdentityUser = Volo.Abp.Identity.IdentityUser;

    namespace Tapp.Web.Pages.Account;

    [Dependency(ReplaceServices = true)] [ExposeServices(typeof(LoginModel))] [DisableAuditing] public class TappLoginModel : LoginModel, ITransientDependency {

    public TappLoginModel(
        IAuthenticationSchemeProvider schemeProvider,
        IOptions&lt;AbpAccountOptions&gt; accountOptions,
        IAbpRecaptchaValidatorFactory recaptchaValidatorFactory,
        IAccountExternalProviderAppService accountExternalProviderAppService,
        ICurrentPrincipalAccessor currentPrincipalAccessor,
        IOptions&lt;IdentityOptions&gt; identityOptions,
        IOptionsSnapshot&lt;reCAPTCHAOptions&gt; reCaptchaOptions) : base(
        schemeProvider,
        accountOptions,
        recaptchaValidatorFactory,
        accountExternalProviderAppService,
        currentPrincipalAccessor,
        identityOptions,
        reCaptchaOptions)
    {
    
    }
    

    }

    @page @using Microsoft.AspNetCore.Mvc.Localization @using Microsoft.Extensions.Options @using Owl.reCAPTCHA @using Volo.Abp.Account.Localization @using Volo.Abp.Account.Public.Web.Pages.Account; @using Volo.Abp.Account.Public.Web.Security.Recaptcha @using Volo.Abp.Account.Settings @using Volo.Abp.Identity; @using Volo.Abp.Settings @model Tapp.Web.Pages.Account.TappLoginModel

    @inject IHtmlLocalizer<AccountResource> L @inject Volo.Abp.AspNetCore.Mvc.UI.Layout.IPageLayout PageLayout @inject ISettingProvider SettingProvider @{ PageLayout.Content.Title = L["Login"].Value; var reCaptchaVersion = await SettingProvider.GetAsync<int>(AccountSettingNames.Captcha.Version); if (Model.UseCaptcha) { await Model.ReCaptchaOptions.SetAsync(reCaptchaVersion == 3 ? reCAPTCHAConsts.V3 : reCAPTCHAConsts.V2); }

    }

    @section scripts { <abp-script-bundle name="@typeof(LoginModel).FullName"> <abp-script src="/Pages/Account/Login.js" /> </abp-script-bundle>

    @if (Model.UseCaptcha)
    {
        if (reCaptchaVersion == 3)
        {
            &lt;recaptcha-script-v3 /&gt;
            &lt;recaptcha-script-v3-js action=&quot;login&quot; execute=&quot;false&quot; /&gt;
        }
        else
        {
            &lt;recaptcha-script-v2 /&gt;
        }
    }
    

    }

    @if (Model.IsLinkLogin) { <abp-alert alert-type="Warning"> @L["LinkAccountWarning", Url.PageLink()] </abp-alert> }

    @if (Model.BackToExternalLogins) { <div class="d-grid gap-2"> <a class="mb-3 btn btn-primary btn-block" href="@Url.Page("./ExternalLogins")">@L["Back"]</a> </div> } <div class="account-module-form">

    @if (Model.IsSelfRegistrationEnabled)
    {
        &lt;h5 class=&quot;mb-2&quot;&gt;@L["NotAMemberYet"] &lt;a class=&quot;text-decoration-none&quot; href=&quot;@Url.Page(&quot;./Register&quot;, new {returnUrl = Model.ReturnUrl, returnUrlHash = Model.ReturnUrlHash})&quot;&gt;@L["Register"]&lt;/a&gt;&lt;/h5&gt;
    }
    
    @if (Model.EnableLocalLogin)
    {
        &lt;form method=&quot;post&quot; id=&quot;loginForm&quot;&gt;
            @if (Model.UseCaptcha)
            {
                &lt;input class=&quot;mb-3&quot; data-captcha=&quot;true&quot; type=&quot;hidden&quot; name=&quot;@RecaptchaValidatorBase.RecaptchaResponseKey&quot; id=&quot;@RecaptchaValidatorBase.RecaptchaResponseKey&quot;/&gt;
            }
            &lt;div&gt;
                &lt;div class=&quot;form-floating mb-2&quot;&gt;
                    &lt;input asp-for=&quot;LoginInput.UserNameOrEmailAddress&quot; type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;name@example.com&quot;&gt;
                    @Html.LabelFor(m => m.LoginInput.UserNameOrEmailAddress, "Email Address")
                    &lt;span asp-validation-for=&quot;LoginInput.UserNameOrEmailAddress&quot;/&gt;
                &lt;/div&gt;
    
                &lt;div class=&quot;form-floating mb-2&quot;&gt;
                    &lt;input asp-for=&quot;LoginInput.Password&quot; id=&quot;password-input&quot; type=&quot;password&quot; class=&quot;form-control&quot; placeholder=&quot;Password&quot;&gt;
                    @Html.LabelFor(m => m.LoginInput.Password)
                    &lt;i id=&quot;PasswordVisibilityButton&quot; class=&quot;bi bi-eye-slash show-pass-icon&quot; data-bs-toggle=&quot;tooltip&quot; data-bs-placement=&quot;top&quot; data-bs-html=&quot;true&quot; aria-label=&quot;@L[&quot;ShowPassword&quot;]&quot; data-bs-original-title=&quot;@L[&quot;ShowPassword&quot;]&quot;&gt;&lt;/i&gt;
                    &lt;i id=&quot;capslockicon&quot; class=&quot;bi bi-capslock caps-lock-icon&quot; style=&quot;display: none;&quot; data-bs-toggle=&quot;tooltip&quot; data-bs-placement=&quot;top&quot; data-bs-html=&quot;true&quot; aria-label=&quot;&lt;i class=&#39;bi bi-exclamation-circle&#39;&gt;&lt;/i&gt; @L["CapsLockOn"]!" data-bs-original-title="&lt;i class=&#39;bi bi-exclamation-circle&#39;&gt;&lt;/i&gt; @L["CapsLockOn"]!">&lt;/i&gt;
                    &lt;span asp-validation-for=&quot;LoginInput.Password&quot;/&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;abp-row&gt;
                &lt;abp-column&gt;
                    &lt;div class=&quot;form-switch ps-2&quot;&gt;
                        &lt;abp-input asp-for=&quot;LoginInput.RememberMe&quot; class=&quot;mb-4&quot;/&gt;
                    &lt;/div&gt;
                &lt;/abp-column&gt;
                &lt;abp-column class=&quot;text-end&quot;&gt;
                    &lt;a href=&quot;@Url.Page(&quot;./ForgotPassword&quot;, new {returnUrl = Model.ReturnUrl, returnUrlHash = Model.ReturnUrlHash})&quot;&gt;@L["ForgotPassword"]&lt;/a&gt;
                &lt;/abp-column&gt;
            &lt;/abp-row&gt;
    
            @if (reCaptchaVersion == 2)
            {
                &lt;script&gt;
                    recaptchaCallback = function (token) {
                        $('form button[type=submit]').removeAttr("disabled");
                        $('#@RecaptchaValidatorBase.RecaptchaResponseKey').val(token)
                    };
                &lt;/script&gt;
                &lt;div class=&quot;mb-3&quot;&gt;
                    &lt;recaptcha-div-v2 callback=&quot;recaptchaCallback&quot;/&gt;
                &lt;/div&gt;
            }
    
            &lt;div class=&quot;d-grid gap-2&quot;&gt;
                &lt;abp-button button-type=&quot;Primary&quot; type=&quot;submit&quot; class=&quot;mb-3&quot; name=&quot;Action&quot; value=&quot;Login&quot; disabled=&quot;true&quot;&gt;
                    &lt;i class=&quot;bi bi-box-arrow-in-right me-1&quot;&gt;&lt;/i&gt;
                    @L["Login"]
                &lt;/abp-button&gt;
            &lt;/div&gt;
    
            @if (Model.ShowCancelButton)
            {
                &lt;div class=&quot;d-grid gap-2&quot;&gt;
                    &lt;abp-button button-type=&quot;Secondary&quot; type=&quot;submit&quot; formnovalidate=&quot;formnovalidate&quot; class=&quot;mb-3&quot; name=&quot;Action&quot; value=&quot;Cancel&quot;&gt;@L["Cancel"]&lt;/abp-button&gt;
                &lt;/div&gt;
            }
        &lt;/form&gt;
    }
    
    @if (Model.VisibleExternalProviders.Any() && false)
    {
        if(Model.EnableLocalLogin)
        {
            &lt;hr/&gt;
            @L["OrSignInWith"]
            &lt;br/&gt;
        }
        else
        {
            @L["SignInWithOneOfTheFollowingProviders"]
        }
    
        &lt;form asp-page=&quot;./Login&quot; asp-page-handler=&quot;ExternalLogin&quot;
              asp-route-returnUrl=&quot;@Model.ReturnUrl&quot;
              asp-route-returnUrlHash=&quot;@Model.ReturnUrlHash&quot;
              asp-route-linkTenantId=&quot;@Model.LinkTenantId&quot;
              asp-route-linkUserId=&quot;@Model.LinkUserId&quot;
              asp-route-linkToken=&quot;@Model.LinkToken&quot;
              method=&quot;post&quot;&gt;
            @foreach (var provider in Model.VisibleExternalProviders)
            {
                &lt;button type=&quot;submit&quot;
                        class=&quot;mt-2 me-2 btn btn-outline-primary btn-sm&quot;
                        name=&quot;provider&quot;
                        value=&quot;@provider.AuthenticationScheme&quot;
                        data-busy-text=&quot;@L[&quot;ProcessingWithThreeDot&quot;]&quot;&gt;
                    @if (provider.Icon != null)
                    {
                        &lt;i class=&quot;@provider.Icon&quot;&gt;&lt;/i&gt;
                    }
                    &lt;span&gt;@provider.DisplayName&lt;/span&gt;
                &lt;/button&gt;
            }
        &lt;/form&gt;
    }
    

    </div>

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    I understand that you don't want to override only the model. If you want to override the complete login page, you can follow the steps below:

    1. Create Account folder in Pages folder like below:

    1. Create Login.cshtml and Login.cshml.cs files in Account folder.
    2. Update Login.cshtml and Login.cshml.cs files like below:

    Login.cshtml

    @page
    @using Microsoft.AspNetCore.Mvc.Localization
    @using Microsoft.AspNetCore.Mvc.TagHelpers
    @using Microsoft.Extensions.Options
    @using Owl.reCAPTCHA
    @using Owl.reCAPTCHA.v2.TagHelpers
    @using Owl.reCAPTCHA.v3.TagHelpers
    @using Volo.Abp.Account.Localization
    @using Volo.Abp.Account.Public.Web.Pages.Account;
    @using Volo.Abp.Account.Public.Web.Security.Recaptcha
    @using Volo.Abp.Account.Settings
    @using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Alert
    @using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Button
    @using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Grid
    @using Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
    @using Volo.Abp.Settings
    @model NonTieredApp.Web.Pages.Account.TappLoginModel
    
    @inject IHtmlLocalizer<AccountResource> L
    @inject Volo.Abp.AspNetCore.Mvc.UI.Layout.IPageLayout PageLayout
    @inject ISettingProvider SettingProvider
    @{
        PageLayout.Content.Title = L["Login"].Value;
        var reCaptchaVersion = await SettingProvider.GetAsync<int>(AccountSettingNames.Captcha.Version);
        if (Model.UseCaptcha)
        {
            await Model.ReCaptchaOptions.SetAsync(reCaptchaVersion == 3 ? reCAPTCHAConsts.V3 : reCAPTCHAConsts.V2);
        }
    
    }
    
    @section scripts
        {
        <abp-script-bundle name="@typeof(LoginModel).FullName">
            <abp-script src="/Pages/Account/Login.js" />
        </abp-script-bundle>
    
        @if (Model.UseCaptcha)
        {
            if (reCaptchaVersion == 3)
            {
                <recaptcha-script-v3 />
                <recaptcha-script-v3-js action="login" execute="false" />
            }
            else
            {
                <recaptcha-script-v2 />
            }
        }
    }
    
    @if (Model.IsLinkLogin)
    {
        <abp-alert alert-type="Warning">
            @L["LinkAccountWarning", Url.PageLink()]
        </abp-alert>
    }
    
    @if (Model.BackToExternalLogins)
    {
        <div class="d-grid gap-2">
            <a class="mb-3 btn btn-primary btn-block" href="@Url.Page("./ExternalLogins")">@L["Back"]</a>
        </div>
    }
    <div class="account-module-form">
    
        @if (Model.IsSelfRegistrationEnabled)
        {
            <h5 class="mb-2">@L["NotAMemberYet"] <a class="text-decoration-none" href="@Url.Page("./Register", new {returnUrl = Model.ReturnUrl, returnUrlHash = Model.ReturnUrlHash})">@L["Register"]</a></h5>
        }
    
        @if (Model.EnableLocalLogin)
        {
            <form method="post" id="loginForm">
                @if (Model.UseCaptcha)
                {
                    <input class="mb-3" data-captcha="true" type="hidden" name="@RecaptchaValidatorBase.RecaptchaResponseKey" id="@RecaptchaValidatorBase.RecaptchaResponseKey"/>
                }
                <div>
                    <div class="form-floating mb-2">
                        <input asp-for="LoginInput.UserNameOrEmailAddress" type="text" class="form-control" placeholder="name@example.com">
                        @Html.LabelFor(m => m.LoginInput.UserNameOrEmailAddress, "Email Address")
                        <span asp-validation-for="LoginInput.UserNameOrEmailAddress"/>
                    </div>
    
                    <div class="form-floating mb-2">
                        <input asp-for="LoginInput.Password" id="password-input" type="password" class="form-control" placeholder="Password">
                        @Html.LabelFor(m => m.LoginInput.Password)
                        <i id="PasswordVisibilityButton" class="bi bi-eye-slash show-pass-icon" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true" aria-label="@L["ShowPassword"]" data-bs-original-title="@L["ShowPassword"]"></i>
                        <i id="capslockicon" class="bi bi-capslock caps-lock-icon" style="display: none;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true" aria-label="<i class='bi bi-exclamation-circle'></i> @L["CapsLockOn"]!" data-bs-original-title="<i class='bi bi-exclamation-circle'></i> @L["CapsLockOn"]!"></i>
                        <span asp-validation-for="LoginInput.Password"/>
                    </div>
                </div>
                <abp-row>
                    <abp-column>
                        <div class="form-switch ps-2">
                            <abp-input asp-for="LoginInput.RememberMe" class="mb-4"/>
                        </div>
                    </abp-column>
                    <abp-column class="text-end">
                        <a href="@Url.Page("./ForgotPassword", new {returnUrl = Model.ReturnUrl, returnUrlHash = Model.ReturnUrlHash})">@L["ForgotPassword"]</a>
                    </abp-column>
                </abp-row>
    
                @if (reCaptchaVersion == 2)
                {
                    <script>
                        recaptchaCallback = function (token) {
                            $('form button[type=submit]').removeAttr("disabled");
                            $('#@RecaptchaValidatorBase.RecaptchaResponseKey').val(token)
                        };
                    </script>
                    <div class="mb-3">
                        <recaptcha-div-v2 callback="recaptchaCallback"/>
                    </div>
                }
    
                <div class="d-grid gap-2">
                    <abp-button button-type="Primary" type="submit" class="mb-3" name="Action" value="Login" disabled="true">
                        <i class="bi bi-box-arrow-in-right me-1"></i>
                        @L["Login"]
                    </abp-button>
                </div>
    
                @if (Model.ShowCancelButton)
                {
                    <div class="d-grid gap-2">
                        <abp-button button-type="Secondary" type="submit" formnovalidate="formnovalidate" class="mb-3" name="Action" value="Cancel">@L["Cancel"]</abp-button>
                    </div>
                }
            </form>
        }
    
        @if (Model.VisibleExternalProviders.Any() && false)
        {
            if(Model.EnableLocalLogin)
            {
                <hr/>
                @L["OrSignInWith"]
                <br/>
            }
            else
            {
                @L["SignInWithOneOfTheFollowingProviders"]
            }
    
            <form asp-page="./Login" asp-page-handler="ExternalLogin"
                  asp-route-returnUrl="@Model.ReturnUrl"
                  asp-route-returnUrlHash="@Model.ReturnUrlHash"
                  asp-route-linkTenantId="@Model.LinkTenantId"
                  asp-route-linkUserId="@Model.LinkUserId"
                  asp-route-linkToken="@Model.LinkToken"
                  method="post">
                @foreach (var provider in Model.VisibleExternalProviders)
                {
                    <button type="submit"
                            class="mt-2 me-2 btn btn-outline-primary btn-sm"
                            name="provider"
                            value="@provider.AuthenticationScheme"
                            data-busy-text="@L["ProcessingWithThreeDot"]">
                        @if (provider.Icon != null)
                        {
                            <i class="@provider.Icon"></i>
                        }
                        <span>@provider.DisplayName</span>
                    </button>
                }
            </form>
        }
    </div>
    

    Login.cshtml.cs

    using Microsoft.AspNetCore.Authentication;
    using Microsoft.AspNetCore.Identity;
    using Microsoft.Extensions.Options;
    using Owl.reCAPTCHA;
    using Volo.Abp.Account.ExternalProviders;
    using Volo.Abp.Account.Public.Web;
    using Volo.Abp.Account.Public.Web.Pages.Account;
    using Volo.Abp.Account.Security.Recaptcha;
    using Volo.Abp.Auditing;
    using Volo.Abp.Security.Claims;
    
    namespace NonTieredApp.Web.Pages.Account;
    
    [DisableAuditing]
    public class TappLoginModel : LoginModel
    {
        public TappLoginModel(
            IAuthenticationSchemeProvider schemeProvider,
            IOptions<AbpAccountOptions> accountOptions,
            IAbpRecaptchaValidatorFactory recaptchaValidatorFactory,
            IAccountExternalProviderAppService accountExternalProviderAppService,
            ICurrentPrincipalAccessor currentPrincipalAccessor,
            IOptions<IdentityOptions> identityOptions,
            IOptionsSnapshot<reCAPTCHAOptions> reCaptchaOptions) : base(
            schemeProvider,
            accountOptions,
            recaptchaValidatorFactory,
            accountExternalProviderAppService,
            currentPrincipalAccessor,
            identityOptions,
            reCaptchaOptions)
        {
    
        }
    }
    

    You can then customize it any way you want.

  • User Avatar
    0
    LiSong created

    That's what I did, and your code has errors. However, if I fix those errors, I still encounter the issue I reported in my original post. Please check my first post.

    public TappLoginModel(
        IAuthenticationSchemeProvider schemeProvider,
        IOptions&lt;AbpAccountOptions&gt; accountOptions,
        IAbpRecaptchaValidatorFactory recaptchaValidatorFactory,
        IAccountExternalProviderAppService accountExternalProviderAppService,
        ICurrentPrincipalAccessor currentPrincipalAccessor,
        IOptions&lt;IdentityOptions&gt; identityOptions,
        IOptionsSnapshot&lt;reCAPTCHAOptions&gt; reCaptchaOptions) : base(
            schemeProvider,
            accountOptions,
            recaptchaValidatorFactory,
            accountExternalProviderAppService,
            currentPrincipalAccessor,
            identityOptions,
            reCaptchaOptions)
    {
    
    }
    
  • User Avatar
    0
    LiSong created

    the action value is null and I got this error:

    An unhandled exception occurred while processing the request. AbpValidationException: ModelState is not valid! See ValidationErrors for details. Volo.Abp.AspNetCore.Mvc.Validation.ModelStateValidator.Validate(ModelStateDictionary modelState)

    Stack Query Cookies Headers Routing AbpValidationException: ModelState is not valid! See ValidationErrors for details. Volo.Abp.AspNetCore.Mvc.Validation.ModelStateValidator.Validate(ModelStateDictionary modelState) Volo.Abp.AspNetCore.Mvc.UI.RazorPages.AbpPageModel.ValidateModel() Tapp.Web.Pages.Account.TappLoginModel.OnPostAsync(string action) in Login.cshtml.cs + ValidateModel(); Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory+GenericTaskHandlerMethod.Convert<T>(object taskAsObject) Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory+GenericTaskHandlerMethod.Execute(object receiver, object[] arguments) Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync() Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync() Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hi,

    I got it, I think the problem is somewhere else. Because when I try the same code, I don't encounter any problems. Can you send your project to berkan.sasmaz@volosoft.com address?

  • User Avatar
    0
    LiSong created

    I've just sent you an email with same subject. thank you so much

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hello,

    First of all, thank you for sending your project. Interestingly, when we override the OnPost method, the action value is not added to the form. I haven't found the root cause, but you can update your Login.js file as follows and continue.

    Login.js:

    $(function () {
    
        var isRecaptchaEnabled = typeof grecaptcha !== 'undefined';
        if (isRecaptchaEnabled) {
            grecaptcha.ready(function () {
                $("#loginForm button[type=submit]").removeAttr("disabled");
            });
        } else {
            $("#loginForm button[type=submit]").removeAttr("disabled");
        }
    
        $("#loginForm button[type=submit]").click(function (e) {
            e.preventDefault();
            var form = $("#loginForm");
            var submitButton = $(this);
    
            var actionInput = $("<input>")
                .attr("type", "hidden")
                .attr("name", "Action")
                .val(submitButton.val());
            form.append(actionInput);
            
            if (form.valid() && isRecaptchaEnabled && abp.utils.isFunction(grecaptcha.reExecute)) {
                grecaptcha.reExecute(function (token) {
                    form.find("input[type=hidden][data-captcha=true]").val(token);
                    abp.ui.setBusy("#loginForm");
                    form.submit();
                })
            } else {
                if (form.valid()){
                    abp.ui.setBusy("#loginForm");
                }
                form.submit();
            }
        });
    
        $("#PasswordVisibilityButton").click(function (e) {
            let button = $(this);
            let passwordInput = $('#password-input');
            if (!passwordInput) {
                return;
            }
    
            if (passwordInput.attr("type") === "password") {
                passwordInput.attr("type", "text");
            }
            else {
                passwordInput.attr("type", "password");
            }
    
            let icon = $("#PasswordVisibilityButton");
            if (icon) {
                icon.toggleClass("bi-eye-slash").toggleClass("bi-eye");
            }
        });
    
        // CAPS LOCK CONTROL
        const password = document.getElementById('password-input');
        const passwordMsg = document.getElementById('capslockicon');
        if (password && passwordMsg) {
            password.addEventListener('keyup', e => {
                if (typeof e.getModifierState === 'function') {
                    passwordMsg.style = e.getModifierState('CapsLock') ? 'display: inline' : 'display: none';
                }
            });
        }
    });
    
  • User Avatar
    0
    LiSong created

    Thanks! it worked, pls also check the register page in my project, it has same issue.

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    You can update your RegisterModel as follows. I override the RegisterLocalUserAsync method in the example, but you can remove it if it is not needed in your case:

    public class MyRegisterModel : RegisterModel
    {
        public MyRegisterModel(IAuthenticationSchemeProvider schemeProvider, IOptions<AbpAccountOptions> accountOptions, IAccountExternalProviderAppService accountExternalProviderAppService, ICurrentPrincipalAccessor currentPrincipalAccessor, IHttpClientFactory httpClientFactory) : base(schemeProvider, accountOptions, accountExternalProviderAppService, currentPrincipalAccessor, httpClientFactory)
        {
        }
    
        protected override async Task<IdentityUser> RegisterLocalUserAsync()
        {
            ValidateModel();
    
            var captchaResponse = string.Empty;
            if (UseCaptcha)
            {
                captchaResponse = HttpContext.Request.Form[RecaptchaValidatorBase.RecaptchaResponseKey];
            }
            var userDto = await AccountAppService.RegisterAsync(
                new RegisterDto
                {
                    AppName = "MVC",
                    EmailAddress = Input.EmailAddress,
                    Password = Input.Password,
                    UserName = Input.UserName,
                    ReturnUrl = ReturnUrl,
                    ReturnUrlHash = ReturnUrlHash,
                    CaptchaResponse = captchaResponse
                }
            );
    
            return await UserManager.GetByIdAsync(userDto.Id);
        }
    }
    
    
  • User Avatar
    0
    LiSong created

    if you ran the project, you can see that it can't pass the validate: ValidateModel()

    the error is(same as the login page):

    An unhandled exception occurred while processing the request. AbpValidationException: ModelState is not valid! See ValidationErrors for details. Volo.Abp.AspNetCore.Mvc.Validation.ModelStateValidator.Validate(ModelStateDictionary modelState)

    Stack Query Cookies Headers Routing AbpValidationException: ModelState is not valid! See ValidationErrors for details. Volo.Abp.AspNetCore.Mvc.Validation.ModelStateValidator.Validate(ModelStateDictionary modelState) Volo.Abp.AspNetCore.Mvc.UI.RazorPages.AbpPageModel.ValidateModel() Tapp.Web.Pages.Account.RegisterModel.RegisterLocalUserAsync() in Register.cshtml.cs + ValidateModel(); Tapp.Web.Pages.Account.RegisterModel.OnPostAsync() in Register.cshtml.cs + user = await RegisterLocalUserAsync(); Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory+GenericTaskHandlerMethod.Convert<T>(object taskAsObject) Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory+GenericTaskHandlerMethod.Execute(object receiver, object[] arguments) Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync() Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync() Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context) Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync() Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ExceptionContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker) Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger) Volo.Abp.AspNetCore.Serilog.AbpSerilogMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+InterfaceMiddlewareBinder+<>c__DisplayClass2_0+<<CreateMiddleware>b__0>d.MoveNext()

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hi,

    Unfortunately, I couldn't reproduce these errors. Here is my account folder:

    https://drive.google.com/file/d/1E0vCbFc7g31d5BXaUrx8UC82_EvJVyT4/view?usp=sharing

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 25, 2025, 11:10