Dynamics CRM 2016 (On-Premise) 调用用户上下文
Dynamics CRM 2016 (On-Premise) calling user context
我正在本地 CRM2016 中开发自定义插件(非沙盒)以与内部 webAPI 交互。
当我 运行 这段代码时,它返回 CRM App Pool 用户而不是我的用户名:
(System.Security.Principal.WindowsIdentity)HttpContext.Current.User.Identity;
这是正常的吗?如果是,如何模拟主叫用户进行外部调用。
谢谢。
是的,这是正常的,Web 服务器上的同步插件 运行,因此预计会获得 IIS 应用程序池用户。如果插件 运行 在后端异步服务上异步 运行s,那么您可能会得到一个不同的服务帐户。
您可以检查插件执行上下文 (IPluginExecutionContext) 以获取 InitiatingUserId
或 UserId
,这是执行插件的系统用户帐户的 CRM GUID - 根据插件的执行和注册方式,这可以为您提供启动插件的用户的 CRM 身份。
Jeff 对此进行了描述; How to get current user record in CRM plugin?
The information is available in the PluginExecutionContext. The code
below is from the Execute method your plugin must implement.
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
Guid userId = context.InitiatingUserId;
}
FYI, the context also has a "UserId" property that may or may not be
the same as the InitiatingUserId. If your plugin step registration
"Run in Users's Context" field has the value "Calling User", then they
will be the same. If you have specified a user in the "Run in User's
Context" field, then the UserId field will contain the user ID of the
person you specify and the InitiatingUserId will be the actual CRM
user whose action triggered the plugin. Sounds like you're looking for
the InitiatingUserId.
或者您可以使用另一个指标,例如最后修改某条记录的人。然后您可以在 CRM 中查找他们的详细信息,例如获取他们的域名。
根据您使用外部服务进行身份验证的方式,这可能有助于模拟用户。否则,据我所知,没有简单的方法来获取用户安全令牌,例如,CRM 并没有真正公开该信息。
我正在本地 CRM2016 中开发自定义插件(非沙盒)以与内部 webAPI 交互。
当我 运行 这段代码时,它返回 CRM App Pool 用户而不是我的用户名:
(System.Security.Principal.WindowsIdentity)HttpContext.Current.User.Identity;
这是正常的吗?如果是,如何模拟主叫用户进行外部调用。
谢谢。
是的,这是正常的,Web 服务器上的同步插件 运行,因此预计会获得 IIS 应用程序池用户。如果插件 运行 在后端异步服务上异步 运行s,那么您可能会得到一个不同的服务帐户。
您可以检查插件执行上下文 (IPluginExecutionContext) 以获取 InitiatingUserId
或 UserId
,这是执行插件的系统用户帐户的 CRM GUID - 根据插件的执行和注册方式,这可以为您提供启动插件的用户的 CRM 身份。
Jeff 对此进行了描述; How to get current user record in CRM plugin?
The information is available in the PluginExecutionContext. The code below is from the Execute method your plugin must implement.
public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); Guid userId = context.InitiatingUserId; }
FYI, the context also has a "UserId" property that may or may not be the same as the InitiatingUserId. If your plugin step registration "Run in Users's Context" field has the value "Calling User", then they will be the same. If you have specified a user in the "Run in User's Context" field, then the UserId field will contain the user ID of the person you specify and the InitiatingUserId will be the actual CRM user whose action triggered the plugin. Sounds like you're looking for the InitiatingUserId.
或者您可以使用另一个指标,例如最后修改某条记录的人。然后您可以在 CRM 中查找他们的详细信息,例如获取他们的域名。
根据您使用外部服务进行身份验证的方式,这可能有助于模拟用户。否则,据我所知,没有简单的方法来获取用户安全令牌,例如,CRM 并没有真正公开该信息。