2015-12-27 3 views
1

Мне нужно преобразовать веб-приложение Kentico 7 в Kentico 8.0.21. Старый код имеет файл CMSModuleLoader в папке App_Code, в котором есть код для события Authenticate_Execute. событие инициализации предложил Kentico не уволятОшибка аутентификации подлинности_Execute в Kentico CMS v8.2

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

У вас есть эти атрибуты, перечисленные выше CMSModuleLoader, как показано в ответе Роки? [AuthenticationHandler] –

ответ

4

Все события связанные с аутентификацией были перемещены в CMS.Membership.SecurityEvents в Kentico 8.0. Использование выглядит следующим образом:

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.

Смежные вопросы