代码之家  ›  专栏  ›  技术社区  ›  Josh Russo

如何调试DNN中的viewstate验证错误?

  •  0
  • Josh Russo  · 技术社区  · 6 年前

    我继承了一个DotNetNuke应用程序,我正在尝试对现有模块进行一些更新。它恰好是一个自定义登录模块。

    我正在尝试集成双因素身份验证。登录本身可以工作,但当我想在之后显示2因素字段时,在提交2因素代码时会出现503错误。

    我试图添加 Application_Error 中的事件 global.asax ,但从未击中。我还试图覆盖 OnError 登录控件的事件,但也从未命中。

    这个 OnInit 在生成503的回发过程中总是被击中,但不是 OnLoad 最奇怪的是如果我跨过 奥尼特 ,直到我在 奥尼特 然后单击“继续”,一切正常。如果我只是从 奥尼特 ,在到达之前,它将与503一起失败 空载 ,几乎每次都是。

    这指向某种异步错误,但我无法想象它可能是什么。

    登录与2因素字段将通过面板控件显示和隐藏,如果这有任何区别的话。

    503错误返回的消息是“当前不存在用于此安装的站点。”

    非常感谢您就如何缩小导致503的原因提出的任何建议。

    使现代化

    我错过了viewstate验证异常的日志条目。

    Validation of viewstate MAC failed. If this application is hosted by a Web
    Farm or cluster, ensure that configuration specifies the same validationKey 
    and validation algorithm. AutoGenerate cannot be used in a cluster. 
    See http://go.microsoft.com/fwlink/?LinkID=314055 for more information.
    

    我设置了机器键值,但仍然得到相同的错误。更不用说,它也不能解释为什么只有在我不介入的情况下才会发生这种情况 奥尼特

    有什么想法吗?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Josh Russo    6 年前

    原来我的问题源于打电话 UserController.UserLogin() 在尝试验证双因素身份验证之前。

    现在我称之为2因素验证后,一切都按预期进行,甚至一致:o)

    密码

    这是一个改变的例子。

    这就是不起作用的地方:

    private void ValidateUser(UserInfo objUser, bool ignoreExpiring)
    {
        UserValidStatus validStatus = UserValidStatus.VALID;
        string strMessage = Null.NullString;
        DateTime expiryDate = Null.NullDate;
        bool okToShowPanel = true;
    
        validStatus = UserController.ValidateUser(objUser, PortalId, ignoreExpiring);
    
        if (PasswordConfig.PasswordExpiry > 0)
        {
            expiryDate = objUser.Membership.LastPasswordChangeDate.AddDays(PasswordConfig.PasswordExpiry);
        }
        UserId = objUser.UserID;
    
        //Check if the User has valid Password/Profile
        switch (validStatus)
        {
            case UserValidStatus.VALID:
                //check if the user is an admin/host and validate their IP
                if (Host.EnableIPChecking)
                {
                    bool isAdminUser = objUser.IsSuperUser || PortalSettings.UserInfo.IsInRole(PortalSettings.AdministratorRoleName); ;
                    if (isAdminUser)
                    {
                        if (IPFilterController.Instance.IsIPBanned(Request.UserHostAddress))
                        {
                            new PortalSecurity().SignOut();
                            AddModuleMessage("IPAddressBanned", ModuleMessage.ModuleMessageType.RedError, true);
                            okToShowPanel = false;
                            break;
                        }
                    }
                }
    
                //Set the Page Culture(Language) based on the Users Preferred Locale
                if ((objUser.Profile != null) && (objUser.Profile.PreferredLocale != null))
                {
                    Localization.SetLanguage(objUser.Profile.PreferredLocale);
                }
                else
                {
                    Localization.SetLanguage(PortalSettings.DefaultLanguage);
                }
    
                //Set the Authentication Type used 
                AuthenticationController.SetAuthenticationType(AuthenticationType);
    
                var userRequestIPAddress = new UserRequestIPAddressController();
                //Complete Login
                UserController.UserLogin(PortalId, objUser, PortalSettings.PortalName, userRequestIPAddress.GetUserRequestIPAddress(new HttpRequestWrapper(Request)), RememberMe);
    
                var twoFactorAuthStatus = GetTwoFactorAuthStatus(objUser);
    
                switch (twoFactorAuthStatus)
                {
                    case TwoFactorAuthStatus.Error:
                        return;
                    case TwoFactorAuthStatus.NotEnabled:
                        RedirectUser(objUser);
                        break;
                    case TwoFactorAuthStatus.SetupNeeded:
                        PageNo = googleAuthSetupPageNo;
                        break;
                    case TwoFactorAuthStatus.VerificationNeeded:
                        PageNo = verifyGoogleAuthPageNo;
                        break;
                }
                break;
            case UserValidStatus.PASSWORDEXPIRED:
                strMessage = string.Format(Localization.GetString("PasswordExpired", LocalResourceFile), expiryDate.ToLongDateString());
                AddLocalizedModuleMessage(strMessage, ModuleMessage.ModuleMessageType.YellowWarning, true);
                PageNo = passwordPageNo;
                pnlProceed.Visible = false;
                break;
            case UserValidStatus.PASSWORDEXPIRING:
                strMessage = string.Format(Localization.GetString("PasswordExpiring", LocalResourceFile), expiryDate.ToLongDateString());
                AddLocalizedModuleMessage(strMessage, ModuleMessage.ModuleMessageType.YellowWarning, true);
                PageNo = passwordPageNo;
                pnlProceed.Visible = true;
                break;
            case UserValidStatus.UPDATEPASSWORD:
                AddModuleMessage("PasswordUpdate", ModuleMessage.ModuleMessageType.YellowWarning, true);
                PageNo = passwordPageNo;
                pnlProceed.Visible = false;
                break;
            case UserValidStatus.UPDATEPROFILE:
                //Save UserID in ViewState so that can update profile later.
                UserId = objUser.UserID;
    
                //When the user need update its profile to complete login, we need clear the login status because if the login is from
                //3rd party login provider, it may call UserController.UserLogin because they doesn't check this situation.
                new PortalSecurity().SignOut();
                //Admin has forced profile update
                AddModuleMessage("ProfileUpdate", ModuleMessage.ModuleMessageType.YellowWarning, true);
                PageNo = profilePageNo;
                break;
        }
        if (okToShowPanel) ShowPanel();
    }
    

    这就是成功的原因:

    private void ValidateUser(UserInfo objUser, bool ignoreExpiring)
    {
        UserValidStatus validStatus = UserValidStatus.VALID;
        string strMessage = Null.NullString;
        DateTime expiryDate = Null.NullDate;
        bool okToShowPanel = true;
    
        validStatus = UserController.ValidateUser(objUser, PortalId, ignoreExpiring);
    
        if (PasswordConfig.PasswordExpiry > 0)
        {
            expiryDate = objUser.Membership.LastPasswordChangeDate.AddDays(PasswordConfig.PasswordExpiry);
        }
        UserId = objUser.UserID;
    
        //Check if the User has valid Password/Profile
        switch (validStatus)
        {
            case UserValidStatus.VALID:
                //check if the user is an admin/host and validate their IP
                if (Host.EnableIPChecking)
                {
                    bool isAdminUser = objUser.IsSuperUser || PortalSettings.UserInfo.IsInRole(PortalSettings.AdministratorRoleName); ;
                    if (isAdminUser)
                    {
                        if (IPFilterController.Instance.IsIPBanned(Request.UserHostAddress))
                        {
                            new PortalSecurity().SignOut();
                            AddModuleMessage("IPAddressBanned", ModuleMessage.ModuleMessageType.RedError, true);
                            okToShowPanel = false;
                            break;
                        }
                    }
                }
    
                var twoFactorAuthStatus = GetTwoFactorAuthStatus(objUser);
    
                switch (twoFactorAuthStatus)
                {
                    case TwoFactorAuthStatus.Error:
                        return;
                    case TwoFactorAuthStatus.NotEnabled:
                        LoginUser(objUser);
                        break;
                    case TwoFactorAuthStatus.SetupNeeded:
                        PageNo = googleAuthSetupPageNo;
                        break;
                    case TwoFactorAuthStatus.VerificationNeeded:
                        PageNo = verifyGoogleAuthPageNo;
                        break;
                }
                break;
            case UserValidStatus.PASSWORDEXPIRED:
                strMessage = string.Format(Localization.GetString("PasswordExpired", LocalResourceFile), expiryDate.ToLongDateString());
                AddLocalizedModuleMessage(strMessage, ModuleMessage.ModuleMessageType.YellowWarning, true);
                PageNo = passwordPageNo;
                pnlProceed.Visible = false;
                break;
            case UserValidStatus.PASSWORDEXPIRING:
                strMessage = string.Format(Localization.GetString("PasswordExpiring", LocalResourceFile), expiryDate.ToLongDateString());
                AddLocalizedModuleMessage(strMessage, ModuleMessage.ModuleMessageType.YellowWarning, true);
                PageNo = passwordPageNo;
                pnlProceed.Visible = true;
                break;
            case UserValidStatus.UPDATEPASSWORD:
                AddModuleMessage("PasswordUpdate", ModuleMessage.ModuleMessageType.YellowWarning, true);
                PageNo = passwordPageNo;
                pnlProceed.Visible = false;
                break;
            case UserValidStatus.UPDATEPROFILE:
                //Save UserID in ViewState so that can update profile later.
                UserId = objUser.UserID;
    
                //When the user need update its profile to complete login, we need clear the login status because if the login is from
                //3rd party login provider, it may call UserController.UserLogin because they doesn't check this situation.
                new PortalSecurity().SignOut();
                //Admin has forced profile update
                AddModuleMessage("ProfileUpdate", ModuleMessage.ModuleMessageType.YellowWarning, true);
                PageNo = profilePageNo;
                break;
        }
        if (okToShowPanel) ShowPanel();
    }
    

    我改变了 RedirectUser() 从第一个示例到 LoginUser() 它还执行重定向。这个 登录用户() 也在成功的双因素身份验证和/或设置后调用。

    一般来说,这是一种更安全的处理方法。我收到的调试反馈只是 超级的 令人沮丧的误导。