The main objective of this nuglet is to list the files associated with modifying the User Welcome and Sign-in links in the upper right-hand page. I always have to look it up in the source, myself. Then one thing follows another and we go into full-blown nuglet mode by demonstrating how the User Welcome control employs the System.Web.UI.ITemplate interface, which is pretty cool, actually.
First to achieve primary nuglet adjectives, the following roadmap gets you to the user welcome control. Skin-TitleBar.ascx contains the Skin-DisplayUserWelcome.ascx control. Skin-DisplayUserWelcome.ascx loads either Skin-AnonymousUserControl.ascx or Skin-RegisteredUserControl.ascx based on the current user IsAnonymous property. Done.
Now for the nuglet's creamy nougat inside, the skin /themes/default/skins/Skin-DisplayUserWelcome.ascx lists two templates.
<CS:LoginView runat="Server">
<AnonymousTemplate>
<CS:AnonymousUserControl runat="Server" />
</AnonymousTemplate>
<LoggedInTemplate>
<CS:RegisteredUserControl runat="Server" />
</LoggedInTemplate>
</CS:LoginView>
The codebehind CS.Controls.LoginView.cs loads the appropriate template based on the current context user.IsAnonymous boolean property. The templates use the System.Web.UI ITemplate interface. According to the ITemplate metadata summary, "Itemplate defines the behavior for populating a templated ASP.NET server control with child controls. The child controls represent the inline templates defined on the page."
The LoginView.cs logic used to determine which template loaded boils down to
ITemplate template = null;
if(CSContext.Current.User.IsAnonymous)
{
template = AnonymousTemplate;
}
else
{
template = LoggedInTemplate;
}
Look again at our Skin-DisplayUserWelcome.ascx above and we see how the Skin-AnonymousUserControl.ascx and Skin-RegisteredUserControl.ascx are loaded appropriately.
When current user is registered user the following HTML code is generated:
<!-- Start: CommunityServer.Controls.DisplayUserWelcome -->
<!-- Skin Path: ~/Themes/default/Skins/Skin-DisplayUserWelcome.ascx -->
<div id="welcome">
<!-- Start: CommunityServer.Controls.RegisteredUserControl -->
<!-- Skin Path: ~/Themes/default/Skins/Skin-RegisteredUserControl.ascx -->
Signed in as
<a href="/user/EditProfile.aspx?ReturnUrl=/Msgs/default.aspx?MessageID=73">
Bill</a> | <a id="ctl00_bhcr_t___Displayuserwelcome1___ctl04___logout"
href="/logout.aspx">
Sign out</a>
<!-- End: CommunityServer.Controls.RegisteredUserControl -->
| <a href="/languages/en-US/docs/faq.aspx">Help</a> |
<a href="/user/PrivateMessages/default.aspx">
Inbox</a>
</div>
<!-- End: CommunityServer.Controls.DisplayUserWelcome -->
---------------------
When current user is anonymous user the following HTML is generated:
<!-- Start: CommunityServer.Controls.DisplayUserWelcome -->
<!-- Skin Path: ~/Themes/default/Skins/Skin-DisplayUserWelcome.ascx -->
<div id="welcome">
<!-- Start: CommunityServer.Controls.AnonymousUserControl -->
<!-- Skin Path: ~/Themes/default/Skins/Skin-AnonymousUserControl.ascx -->
Welcome to Community Server
<a id="ctl00_bhcr_t___Displayuserwelcome1___ctl04___Login"
href="/login.aspx?ReturnUrl=%2flogin.aspx%3fReturnUrl">Sign in</a> |
<a id="ctl00_bhcr_t___Displayuserwelcome1___ctl04___Register"
href="/user/CreateUser.aspx?ReturnUrl=/login.aspx?ReturnUrl">Join</a>
<!-- End: CommunityServer.Controls.AnonymousUserControl -->
| <a href="/languages/en-US/docs/faq.aspx">Help</a>
</div>
<!-- End: CommunityServer.Controls.DisplayUserWelcome -->