SharePoint中如何获得当前用户的loginName
选了解一下其属性。
SPUser.LoginName Property (Microsoft.SharePoint)
Gets the user name of the user. Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll) Syntax
Property ValueA string that contains the user name.
See Also
ReferenceSPUser Class
SPUser Members
Microsoft.SharePoint Namespace
参考:http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.loginname.aspx
如此解决:How to get the current user logged into Sharepoint
the following snippet get the current user lgged into Sharepoint and displays his/her Name, Login name, Email and all the groups he/she belongs to.
try {SPWeb web = SPControl.GetContextWeb(Context);SPUser sUser = web.CurrentUser; string str = "Name:" + sUser.Name + "<BR>"; "Login Name :" + sUser.LoginName + "<BR>"; "Email:" + sUser.Email + "<BR>"; "Groups:" + sUser.Groups.Count + "<BR>"; foreach (SPGroup grp in sUser.Groups) { " * " + grp.Name + " total Members:" + grp.Users.Count + "<BR>"; catch (Exception ex) { "No Current User" ;
str +=
str +=
str +=
str +=
}
lblInfo.Text = str;
}
lblInfo.Text=
}
http://geekswithblogs.net/shervin/archive/2008/05/19/122238.aspx
SPUser.LoginName Property (Microsoft.SharePoint)
Gets the user name of the user. Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll) Syntax
Visual Basic (Declaration) |
Public ReadOnly Property LoginName As String |
Visual Basic (Usage) |
Dim instance As SPUserDim value As Stringvalue = instance.LoginName |
C# |
public string LoginName { get; } |
Property ValueA string that contains the user name.
See Also
ReferenceSPUser Class
SPUser Members
Microsoft.SharePoint Namespace
参考:http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.loginname.aspx
如此解决:How to get the current user logged into Sharepoint
the following snippet get the current user lgged into Sharepoint and displays his/her Name, Login name, Email and all the groups he/she belongs to.
try {SPWeb web = SPControl.GetContextWeb(Context);SPUser sUser = web.CurrentUser; string str = "Name:" + sUser.Name + "<BR>"; "Login Name :" + sUser.LoginName + "<BR>"; "Email:" + sUser.Email + "<BR>"; "Groups:" + sUser.Groups.Count + "<BR>"; foreach (SPGroup grp in sUser.Groups) { " * " + grp.Name + " total Members:" + grp.Users.Count + "<BR>"; catch (Exception ex) { "No Current User" ;
str +=
str +=
str +=
str +=
}
lblInfo.Text = str;
}
lblInfo.Text=
}
http://geekswithblogs.net/shervin/archive/2008/05/19/122238.aspx