Show name of who is logged in

Nov 22, 2007 at 2:31 AM
Is there a way to show the name of who is logged in? Like is done at the top of the CodePlex pages? Useful when one has more than one identity for testing.

-----Paul-----
Nov 23, 2007 at 2:27 AM
Edited Nov 23, 2007 at 2:31 AM
You should be able to use Page.User.Identity.Name. If you add the code in the aspx use <asp:LoginName ID="LoginName1" runat="server" FormatString="Welcome {0}" />.
Nov 24, 2007 at 6:41 AM
Thank you. I am sure that would be the right answer for someone who understood theme design. Unfortunately, I have no idea how to implement that.

I tried putting the line into default.aspx but anywhere I put it simply caused an error which would prevent BE from loading at all. Other than trying to learn ASP.NET programming, is there a tutorial on how to modify BE's operation?

-----Paul-----




lvildosola wrote:
You should be able to use Page.User.Identity.Name. If you add the code in the aspx use <asp:LoginName ID="LoginName1" runat="server" FormatString="Welcome {0}" />.

Nov 24, 2007 at 12:03 PM
Edited Nov 24, 2007 at 12:04 PM
I understand. What you will want to do is place the code in the master template of the theme you want to modify. The name of this file is site.master and it can be found in the folder themes/NameOfTheme.

Let's assume that you want to place the name of the currently logged in user beside the Sign out message and this is all part of the top menu. You would have code like the following in the master template.

<div id="navbar">
    <a id="A1" href="~/" runat="server" rel="home"><%= Resources.labels.home %></a> |
    <a id="A2" href="~/archive.aspx" runat="server"><%= Resources.labels.archive %></a> |
    <a id="A3" href="~/contact.aspx" runat="server"><%= Resources.labels.contact %></a> |
    <a href="<%=Utils.FeedUrl %>" target="_blank" class="feed"><img src="<%= Utils.RelativeWebRoot %>pics/rssbutton.gif" alt="Feed" /><%= Resources.labels.subscribe %></a> |
    <asp:LoginName ID="lnUser" runat="server" FormatString="({0})" />
    <asp:LoginStatus ID="LoginStatus1" runat="Server" LoginText="Sign in" LogoutText="Sign out" EnableViewState="false" />
</div>
You can see the use of the asp:LoginName and asp:LoginStatus in the example above. Now, when your top menu renders you will either see Sign in (if the user is not logged in yet) or (User Name) Sign out (if the user is logged in.
Nov 26, 2007 at 4:27 AM
Your code works wonderfully. I am playing with DarkBlog and it fits right in.

But I have a learning question. Your initial answer referred to Page.User.Identity.Name but your code shows no reference to this value. How does this work?

Thank you for your help.

----Paul-----
Nov 26, 2007 at 5:06 AM
There are 2 places where you can put code. One place is the .aspx page (the example shown above does this). The other place is in the page code behind (.aspx.cs). The Page.User.Identity.Name call would be used if you were placing logic in the page code behind. To clarify it, the code behind is the file with the .aspx.cs extension that has the same name as the .aspx page where you want to see the logic apply.