As ScottS said, if you use standard login controls and a membership provider, this information is already available to you in User.Identity.Name.
The only reason I am posting the response is to mark the LoginName control, which you can delete on the page / page master and do it automatically for you:
<asp:LoginName id="LoginName1" runat="server" FormatString ="Welcome, {0}" />
This will result in "Welcome, Zhaph" when the user logs in, or nothing if they are not.
You can also combine this with LoginView and LoginStatus :
<asp:LoginView ID="RegisterLink" runat="server"> <AnonymousTemplate> <div class="titleRegistration"> <a href="/Users/Register.aspx">Register</a> or </div> </AnonymousTemplate> <LoggedInTemplate> <div class="titleRegistration"> Welcome back <asp:LoginName ID="LoginName1" runat="server" /> - </div> </LoggedInTemplate> </asp:LoginView> <asp:LoginStatus ID="lsGeneral" runat="server" LogoutPageUrl="/Users/Logout.aspx" />
This combination of controls will do the following:
- If the user is not registered on the display: register or log in
- If the user is logged in on the display: Welcome back Zhaph - Logout
Login lines are populated with settings in web.config and generated by the LoginStatus control.
source share