在APP中获取sharepoint 2013自动主播应用的当前用户 [英] Get Current User in APP for sharepoint 2013 autohosted app

查看:73
本文介绍了在APP中获取sharepoint 2013自动主播应用的当前用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我吗?我正在为sharepoint 2013做一些实验室应用程序而且我无法返回应用程序的当前用户。当我返回当前用户时,代码总是返回管理员。有没有人遇到过这个问题?

can anyone help me? I'm doing some labs apps for sharepoint 2013 and I can not return the current user of an app. the code always returns the administrator when I return the current user. Has anyone encountered this problem?

以下是我正在使用的代码:

Following is the code I'm using:

     static ClientContext context = new ClientContext(" full url");

    static ClientContext context = new ClientContext("full url");

           用户usuarioAtual = context.Web.CurrentUser;

            context.Load(usuarioAtual);

            User usuarioAtual = context.Web.CurrentUser;
            context.Load(usuarioAtual);

context.ExecuteQuery();

context.ExecuteQuery();

推荐答案

我遇到同样的问题,我的代码返回运行IE的用户。登录不同的用户(以不同用户身份登录)后,代码显示错误的用户名。

I have the same problem, my code returns user on which I run IE. After logging on a diferent user(Sign in as a Diferent User) the code display wrong user name.

var context;
var web;
var user;

// This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model


(document).ready(function (){
context = SP.ClientContext.get_current();
web = context.get_web();

getUserName();
});

//此函数准备,加载,然后执行SharePoint查询以获取当前用户信息
function getUserName(){
user = web.get_currentUser();
context.load(user);
context.executeQueryAsync(onGetUserNameSuccess,onGetUserNameFail);
}

//如果上述OM调用成功,则执行此函数
//用用户名
替换'helloString'元素的内容function onGetUserNameSuccess(){
(document).ready(function () { context = SP.ClientContext.get_current(); web = context.get_web(); getUserName(); }); // This function prepares, loads, and then executes a SharePoint query to get the current users information function getUserName() { user = web.get_currentUser(); context.load(user); context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail); } // This function is executed if the above OM call is successful // It replaces the contents of the 'helloString' element with the user name function onGetUserNameSuccess() {


('#message')。text('Hello'+ user.get_title());
}

//如果上述调用失败,则执行此函数
函数onGetUserNameFail(sender,args){
alert('无法获取用户名。错误:'+ args.get_message());
}
('#message').text('Hello ' + user.get_title()); } // This function is executed if the above call fails function onGetUserNameFail(sender, args) { alert('Failed to get user name. Error:' + args.get_message()); }


这篇关于在APP中获取sharepoint 2013自动主播应用的当前用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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