[英]CRM 2013 - Plugin Execution (Post Operation) What happens and when?
I have a system configuration entity where I store credentials of a Web Service. 我有一个系统配置实体,在其中存储Web服务的凭据。 I need to encrypt the password field (new_SharePointServicePassword) and I want my plugin to do the encryption.
我需要加密密码字段(new_SharePointServicePassword),并且我希望我的插件进行加密。
So, I have created a new assembly with the following events registered. 因此,我创建了一个新的程序集,并注册了以下事件。
base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "new_systemconfiguration", new Action<LocalPluginContext>(ExecutePostSystemConfigurationCreate)));
base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "new_systemconfiguration", new Action<LocalPluginContext>(ExecutePostSystemConfigurationCreate)));
My plugin code is as below. 我的插件代码如下。
string plainTextPassword = SystemConfiguration.new_SharePointServicePassword;
string encryptedPassword;
this.TracingService.Trace("Generating Keys");
Encryption encryption = new Encryption(localContext.PluginExecutionContext.OrganizationId.ToString());
this.TracingService.Trace("Generating Keys - Completed");
if (!string.IsNullOrEmpty(plainTextPassword))
{
this.TracingService.Trace("Encrypting password");
encryptedPassword = encryption.Encrypt(plainTextPassword);
this.TracingService.Trace("Encrypting password - Completed");
SystemConfiguration.new_SharePointServicePassword = encryptedPassword;
localContext.OrganizationService.Update(SystemConfiguration);
}
The steps registered against the Plugin are for Post Operation for both Create and Update messages. 针对插件注册的步骤适用于创建和更新消息的后期操作。 The Update message is filtered on the new_SharePointServicePassword attribute.
更新消息在new_SharePointServicePassword属性上进行过滤。
Questions 问题
localContext.OrganizationService.Update(SystemConfiguration);
localContext.OrganizationService.Update(SystemConfiguration);
required? I would recommend you to run the plugin on Pre Operation
. 我建议您在
Pre Operation
上运行插件。 Because when you enter the password through UI, it will save the unencrypted password first. 因为当您通过UI输入密码时,它将首先保存未加密的密码。 User will have to refresh to see the encryption.
用户将必须刷新才能看到加密。 Also if you have auditing enabled on password field.
另外,如果您在密码字段上启用了审核。 It will show the unencrypted password in Audit log.
它将在审核日志中显示未加密的密码。 On
Pre Operation
you don't need following line: 在“
Pre Operation
您不需要执行以下Pre Operation
:
localContext.OrganizationService.Update(SystemConfiguration);
Make sure that you replace 40
with 20
in your code. 确保在代码中将
40
替换为20
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.