SharePoint offers a couple of ways by which we can obtain the current user for use in a XSLT web part like DataFormWebPart or XsltListViewWebPart. All involve first setting parameters through the ParameterBindings property:
1:<ParameterBindings>
2:<ParameterBindingName="UserID"Location="CAMLVariable"DefaultValue="CurrentUserName"/>
3:<ParameterBindingName="LogonUser_"Location="WPVariable(_LogonUser_)"/>
4:<ParameterBindingName="LogonUser"Location="ServerVariable(LOGON_USER)"/>
5:<ParameterBindingName="AuthUser"Location="ServerVariable(AUTH_USER)"/>
6:<ParameterBindingName="RemoteUser"Location="ServerVariable(REMOTE_USER)"/>
7:</ParameterBindings>
8:<Xsl>
9:<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:msxsl="urn:schemas-microsoft-com:xslt"exclude-result-prefixes="msxsl asp"xmlns:asp="System.Web.UI.WebControls"xmlns:ddwrt2="urn:frontpage:internal"xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
10:<xsl:outputmethod="html"/>
11:<xsl:paramname="UserID"/>
12:<xsl:paramname="LogonUser_"/>
13:<xsl:paramname="LogonUser"/>
14:<xsl:paramname="AuthUser"/>
15:<xsl:paramname="RemoteUser"/>
16:<xsl:templatematch="/">
17: UserID: <xsl:value-ofselect="$UserID"/><br/>
18: ID: <xsl:value-ofselect="ddwrt:UserLookup($UserID, 'ID')"/><br/>
19: EMail: <xsl:value-ofselect="ddwrt:UserLookup($UserID, 'EMail')"/><br/>
20: Login: <xsl:value-ofselect="ddwrt:UserLookup($UserID, 'Login')"/><br/>
21: LogonUser_: <xsl:value-ofselect="$LogonUser_"/><br/>
22: AuthUser: <xsl:value-ofselect="$AuthUser"/><br/>
23: RemoteUser: <xsl:value-ofselect="$RemoteUser"/><br/>
24:</xsl:template>
25:</xsl:stylesheet>
26:</Xsl>
Here we see different kinds of parameters:
- CAMLVariable: built in variables UserID and Today;
- WPVariable: returns one of the predefined values for _WPID_ (web part client id), _WPQ_ (web part unique id in page), _WPR_ (web part resources folder full URL), _WPSRR_ (web part resources folder relative URL), _LogonUser_ (server variable LOGON_USER), _WebLocaleId_ (current site locale, as in CultureInfo.LCID);
- ServerVariable: returns one of the HTTP or IIS server- defined variables.
This will return something like this:
UserID: Ricardo Peres
ID: 10
EMail: ricardoperes@domain.com
Login: i:0#.w|DOMAIN\ricardoperes
LogonUser_: 0#.w|DOMAIN\ricardoperes
AuthUser: 0#.w|DOMAIN\ricardoperes
RemoteUser: 0#.w|DOMAIN\ricardoperes
The ddwrt:UserLookup extension function returns a value depending on the second parameter; valid values are Id, Email and Login, and you can easily guess what they are for.
You can find a reference for LOGON_USER, AUTH_USER, REMOTE_USER and UNMAPPED_REMOTE_USERhere. In my development server, I get the same value for all variables.
By the way, I posted a more advanced solution, which allows access to any profile properties. You can read it here.