Kentico CMS v8.2中的Authenticate_Execute事件覆盖

时间:2015-12-27 10:05:17

标签: c# kentico

我需要将Kentico 7 Web应用程序转换为Kentico 8.0.21。旧代码在App_Code文件夹中有一个CMSModuleLoader文件,该文件包含Authenticate_Execute事件的代码。 kentico建议的init事件不会被解雇

public partial class CMSModuleLoader
{
private class AuthenticationHandler : CMSLoaderAttribute
{
    /// <summary>
    /// Called automatically when the application starts
    /// </summary>
    public override void Init()
    {
        // Assigns a handler to the SecurityEvents.Authenticate.Execute event
        // This event occurs when users attempt to log in on the website
        SecurityEvents.Authenticate.Execute += OnAuthentication;
    }
    private void OnAuthentication(object sender, AuthenticationEventArgs args)
    {
        if (args.User != null) //the authenticate was successful
        {
            try
            {
                var accountFacade = WebContainer.Instance.Container.GetInstance<IAccountFacade>();
                accountFacade.ReconcileOnLogin(args.UserName);
            }
            catch (Exception e)
            {
                var logger = LogManager.GetCurrentClassLogger();
                var ex = new Exception("IAccountFacade.ReconcileOnLogin method throw an error communicating with dynamics, the issue is not resolvable from Kentico thus regardless of the permission level of the current user, the exception will be bubbled up and the user will be shown error details or the custom error page.", e);
                logger.Fatal(x => x("The current exception is caused by dynamics/data problems and the user will not be allowed to login. A system admin with access to dynamics is required to resolve the problem.", e));
                throw ex;
            }
            //ResetPasswordAttempts(args.User);
        }
    }
}

/// <summary>
/// Attribute class that ensures the loading of custom handlers
/// </summary>
private class CustomSecurityEventsAttribute : CMS.Base.CMSLoaderAttribute
{
    /// <summary>
    /// Called automatically when the application starts
    /// </summary>
    public override void Init()
    {
        SecurityEvents.Authenticate.Execute += new     EventHandler<AuthenticationEventArgs>(Authenticate_Execute);
    }

    /// <summary>
    /// called on every kentico authenticate attempt
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>

1 个答案:

答案 0 :(得分:4)

所有与身份验证相关的事件都已移至Kentico 8.0中的CMS.Membership.SecurityEvents。用法如下:

using System.Data;

using CMS.Base;
using CMS.Membership;
using CMS.DataEngine;

[AuthenticationHandler]
public partial class CMSModuleLoader
{
    /// <summary>
    /// Custom attribute class.
    /// </summary>
    private class AuthenticationHandler : CMSLoaderAttribute
    {
        /// <summary>
        /// Called automatically when the application starts
        /// </summary>
        public override void Init()
        {
            // Assigns a handler to the SecurityEvents.Authenticate.Execute event
            // This event occurs when users attempt to log in on the website
            SecurityEvents.Authenticate.Execute += OnAuthentication;
        }
    }
}

有关详细信息,请参阅documentation