您可以找到当前用户的用户名和其他内容。为此,首先在 .aspx 页面的顶部添加这一行:<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
(Version=14.0.0.0对于 Sharepoint 2010 和Version=12.0.0.0对于 Sharepoint 2007)
现在,在<form>标签之后添加这一行:
<form>
<SPSWC:ProfilePropertyLoader runat="server"/>
</form>最后在标记前添加以下块:
<div id="userDetails" style="display:none">
<asp:LoginName runat="server" id="userLogin">
<SPSWC:ProfilePropertyValue PropertyName="FirstName" ApplyFormatting="false" id="userFirstName" runat="server"/>
<SPSWC:ProfilePropertyValue PropertyName="LastName" ApplyFormatting="false" id="userLastName" runat="server"/>
<SPSWC:ProfilePropertyValue PropertyName="WorkEmail" ApplyFormatting="false" id="userWorkEmail" runat="server"/>
<SPSWC:ProfilePropertyValue PropertyName="PreferredName" ApplyFormatting="false" id="userPreferredName" runat="server"/>
</div>
因此,在您的页面中,您将看到一个“userDetails”块,其中包含当前用户登录名、名字、姓氏、工作电子邮件和首选名称。使用 JavaScript,您可以通过以下方式获取用户名:
document.getElementById('ctl00_userLogin').innerHTML