Display Logged in User Name in Share Point 2010 Master Page for FBA using Javascript
January 21, 2011 Leave a comment
We tried to display the user name of the logged in user in a SharePoint 2010 Master Page using Asp:LoginView control, but it always displays as “ i:0#.f|acaspnetsqlmembershipprovider|aritra”. Our site was set up for Form Based Authentication.
Following is the solution which worked fine for us, and it uses JavaScript only for this:-
1. Open the web.config of the SharePoint 2010 site and add the following in the configuration/SharePoint/PageParserPaths configuration section:
<PageParserPaths>
<PageParserPath VirtualPath=”~/_layouts/masterpages/myCustomMaster.master” CompilationMode=”Always” AllowServerSideScript=”true” />
</PageParserPaths>
This is because we are adding inline code in a master-page
2. Insert the following markup in the appropriate section of your Master Page
Welcome, <script type=”text/javascript”>var loginName = “<%= SPContext.Current.Web.CurrentUser.Name %>”;document.write(loginName);</script>