从自定义页面访问登录的CRM用户 [英] accessing the logged in CRM user from custom page

查看:62
本文介绍了从自定义页面访问登录的CRM用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有Dynamics CRM和从功能区加载的Web表单,本质上是在iframe中。

We have Dynamics CRM and a webform which is loaded from the ribbon, essentially inside an iframe.

我们如何获得登录用户?在右上角是通过Active Directory登录的我的名字和图像。但是,如果执行以下操作:

How do we get the logged on user? On the top right, is my name and image as logged in via Active Directory. However, if I do something like:

var UserID = window.parent.Xrm.Page.context.getUserId();

或在C#中:

UserPrincipal user = UserPrincipal.Current; 
lblUser.Text = user.SamAccountName;

然后我们获得配置为使用CRM的通用用户。

then we get the generic user that CRM is configured to use.

如果我右键单击整个表单并转到查看源代码,则可以看到以下内容:

If I do a right click on the entire form and go "View Source", I can see this:

var USER_NAME = 'Rodney Ellis';

在Chrome的开发人员工具中,我可以从控制台中运行它,并显示我的名字:

In Chrome's developer tools I can run this from the Console, and my name appears:

alert(USER_NAME);

但是当我尝试从代码中的javascript访问它时,它说找不到:
未捕获ReferenceError:未定义USER_NAME

But when I try to access it from javascript in the code it says it can't be found: Uncaught ReferenceError: USER_NAME is not defined

如何通过c#或js从aspx网络表单中获取用户名?跨语言脚本被阻止已经停止了许多简单的方法,因此为什么我们要寻找解决方法。

How can I get the Username from inside the aspx webform, either by c# or js? Cross-side scripting being blocked has stopped a lot of the easy ways, hence why we're looking for a work-around.

推荐答案

在有史以来的重大黑客事件中,我们通过将另一个iFrame嵌入到Web资源中来解决了这个问题!

In one of the all time great hacks ... we got around the problem by embedding another iFrame into a web resource!

因此,Web资源可以调用Xrm.Page.context.getUserName(),然后将其连接到querystring,然后将其传递给iFrame。因为CRM认为iframe只是一个控件,所以它允许在其中执行所有webform命令,并且不会出现任何500个错误。

So the web resource can call Xrm.Page.context.getUserName() and then concatenate that to the querystring which we then pass into an iFrame. because CRM thinks the iframe is just one control, it allows all the webform commands taking place inside of it and doesn't give any 500 errors.

这篇关于从自定义页面访问登录的CRM用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆