从自定义事件处理程序插入自定义表格项时遇到问题

问题描述 投票:0回答:1

我遇到了一个问题,希望有人可以帮助我。我们使用带有 Windows 身份验证的 Kentico 12 sp。我们需要在属于特定角色的用户进行身份验证时进行记录。我为 SecurityEvents.Authenticate.Execute 创建了一个自定义事件处理程序。

 if (e.User.IsInRole("bsi-sfr-lg-hcwp_patientroster", "Internal") || e.User.SiteIndependentPrivilegeLevel.Equals(UserPrivilegeLevelEnum.GlobalAdmin))
 {
     string EIN = e.User.UserName.Substring(4, 6);
     U.SamAccountName = EIN;
     PrincipalSearcher searcher = new PrincipalSearcher(U);
     UserPrincipal principal = (UserPrincipal)searcher.FindOne();
     if (principal != null)
     {
         Login = principal.DisplayName;
     }
     else
     {
         Login = "Error getting Name";
     }
     DataClassInfo classInfo = DataClassInfoProvider.GetDataClassInfo(AuthenticationLogTable);
     if (classInfo != null)
     {
         CustomTableItem NewAuthLog = new CustomTableItem(AuthenticationLogTable);
         NewAuthLog.SetValue("Login", e.User.UserName);
         NewAuthLog.SetValue("DisplayName", Login);
         if (e.User.SiteIndependentPrivilegeLevel.Equals(UserPrivilegeLevelEnum.GlobalAdmin))
             NewAuthLog.SetValue("UserRole", "Global Admin");
         else if (e.User.IsInRole("bsi-sfr-lg-hcwp_patientroster", "Internal"))
             NewAuthLog.SetValue("UserRole", "bsi-sfr-lg-hcwp_patientroster");
         // Add additional roles here as an else if
         
         NewAuthLog.Insert();
     }
 }

当到达 NewAuthLog.Insert 时,我收到错误

Description:at CMS.CustomTables.CustomTableItem.InsertData()
at CMS.DataEngine.AbstractInfoProvider`3.SetInfo(TInfo info)
at CustomAuthenticationHandler.OnAuthentication(Object sender, AuthenticationEventArgs e) in C:\Sites\internal-test.vitalant.org\server\CMS\App_Code\_CustomHandlers\CustomAuthenticationHandler.cs:line 68

在尝试通过获取 NewAuthLog 中的各个字段来插入记录之前,我确实添加了一个 LogEvent 条目,并且它们按照我的预期填充了事件日志中的描述。

kentico
1个回答
0
投票

布莱恩- 您收到的实际错误是什么?您仅提供了部分堆栈跟踪。

创建新的 CustomTableItem 实例:

CustomTableItem NewAuthLog = CustomTableItem.New(AuthenticationLogTable);

此外,请确保将数据添加到所有需要数据的字段。

https://docs.xperience.io/api12sp/content-management/custom-table-data#Customtabledata-Addingdatarecordstoacustomtable

© www.soinside.com 2019 - 2024. All rights reserved.