sharepoint中当前登录用户的名称

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sharepoint中当前登录用户的名称相关的知识,希望对你有一定的参考价值。

Returns the username (domainusername) of the user that is currently logged in sharepoint. Can be used inside features / custom pages
  1. /// <summary>
  2. /// Returns the username of the currently logged in user
  3. /// </summary>
  4. private string CurrentUserName()
  5. {
  6. string userName = "NA";
  7. SPContext currentContext;
  8. try
  9. {
  10. //Getting the current context
  11. currentContext = SPContext.Current;
  12. }
  13. catch (InvalidOperationException)
  14. {
  15. currentContext = null;
  16. }
  17. if (currentContext != null && currentContext.Web.CurrentUser != null)
  18. {
  19. userName = SPContext.Current.Web.CurrentUser.LoginName;
  20. }
  21.  
  22. return userName;
  23. }

以上是关于sharepoint中当前登录用户的名称的主要内容,如果未能解决你的问题,请参考以下文章

SharePoint 2010使用SPServices获取用户标识

SharePoint 2013 使用 JavaScript 获取当前用户

错误:名称在当前上下文中不存在(Webpart、C#、Visual Studios、SharePoint 2010)

Sharepoint 上的模拟全文搜索(无密码)

我们如何使用 C# 在 SharePoint 中获取当前的身份验证模式

PHP / SQL在表单完成时存储当前登录用户的名称