Show login name in asp.net
LoginName is an ASP.NET web server control. LoginName control allows us
to display a user's login name if the user has logged in using ASP.NET
membership. If the site uses integrated windows authentication, the LoginName
control displays the user's windows account name.
LoginName class allows us to display System.Web.UI.Page.User.Identity.Name property value. LoginName class exists in System.Web.UI.WebControls namespace.
LoginName control has many useful built-in properties to provide a better user experience such as AccessKey, BackColor, BorderColor, Attributes, BorderStyle, BorderWidth, CssClass, Font, ForeColor, FormatString, HasAttributes, Height, IsEnabled, Page, Parent, SkinID, Style, TabIndex, TagKey, ToolTip, ViewState, Visible, Width, etc.
LoginName control has a few events such as DataBinding, Disposed, Int, Load, PreRender, and Unload.
LoginName class’s FormatString property allows us to provide a format item string to display. FormatString property value data type is String. This value represents a string containing format items for displaying the user's name. The default value of the FormatString property is "{0}".
This FormatString property contains a standard text format string. the string "(0)" indicates where in the string the user's name is inserted. FormatString property throws a FormatException exception if the format String is not valid.
The following ASP.NET C# example code demonstrates to us how can we display the logged-in user's name on a web page using LoginName server control in an ASP.NET application.
LoginName class allows us to display System.Web.UI.Page.User.Identity.Name property value. LoginName class exists in System.Web.UI.WebControls namespace.
LoginName control has many useful built-in properties to provide a better user experience such as AccessKey, BackColor, BorderColor, Attributes, BorderStyle, BorderWidth, CssClass, Font, ForeColor, FormatString, HasAttributes, Height, IsEnabled, Page, Parent, SkinID, Style, TabIndex, TagKey, ToolTip, ViewState, Visible, Width, etc.
LoginName control has a few events such as DataBinding, Disposed, Int, Load, PreRender, and Unload.
LoginName class’s FormatString property allows us to provide a format item string to display. FormatString property value data type is String. This value represents a string containing format items for displaying the user's name. The default value of the FormatString property is "{0}".
This FormatString property contains a standard text format string. the string "(0)" indicates where in the string the user's name is inserted. FormatString property throws a FormatException exception if the format String is not valid.
The following ASP.NET C# example code demonstrates to us how can we display the logged-in user's name on a web page using LoginName server control in an ASP.NET application.
Login.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>LoginName Example: How to show login name in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8"
BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#333333">
<TextBoxStyle Font-Size="0.8em" />
<LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775" />
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.9em"
ForeColor="White" />
</asp:Login>
</div>
</form>
</body>
</html>
Default.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Using LoginName Control</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Wellcome my site</h1>
<asp:LoginStatus ID="LoginStatus1" runat="server" />
<br />
<asp:LoginName ID="LoginName1" runat="server" FormatString="{0} logged in." Font-Size="Medium" ForeColor="BlueViolet" />
<br /><br />
<asp:LoginName ID="LoginName2" runat="server" FormatString="Hi {0}!" Font-Size="XX-Large" ForeColor="Crimson" />
</div>
</form>
</body>
</html>

