Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
LoginName Class
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
LoginName Class

Updated: November 2007

Displays the value of the System.Web.UI.Page.User.Identity.Name property.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

Visual Basic (Declaration)
<BindableAttribute(False)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class LoginName _
    Inherits WebControl
Visual Basic (Usage)
Dim instance As LoginName
C#
[BindableAttribute(false)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class LoginName : WebControl
Visual C++
[BindableAttribute(false)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class LoginName : public WebControl
J#
/** @attribute BindableAttribute(false) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class LoginName extends WebControl
JScript
public class LoginName extends WebControl
ASP.NET
<asp:LoginName />

By default, the LoginName control displays the name contained in the User property of the Page class. If the System.Web.UI.Page.User.Identity.Name property is empty, the control is not rendered.

Note:

If you are not familiar with the set of login controls available in ASP.NET, see ASP.NET Login Controls Overview before continuing. For a list of other topics related to login controls and membership, see Managing Users by Using Membership.

To change the text displayed by the LoginName control, set the FormatString property.

Note:

The LoginName control cannot be used outside the <form> tag on a Web page. Specifically, the LoginName cannot be used to put the user's name in the title of a page.

Accessibility

The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

TopicLocation
How to: Display the Name of the Current UserBuilding ASP .NET Web Applications
How to: Display the Name of the Current UserBuilding ASP .NET Web Applications
How to: Display the Name of the Current UserBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Managing Web Site Users with RolesBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Managing Web Site Users with RolesBuilding Applications with Visual Web Developer

The following code example shows how to use the LoginName class on a page. Clicking the button changes the display format.

Visual Basic
<%@ Page Language="VB" autoeventwireup="False" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    Sub Button1_Click(sender As Object, e As EventArgs) 
        LoginName1.FormatString = "Welcome to our Web site, {0}"
         Button1.Visible = false
    End Sub

</script>
<html  >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <p>
            <asp:LoginName id="LoginName1" runat="server" 
               FormatString="Welcome, {0}" />
        </p>
        <p>
            <asp:Button id="Button1" onclick="Button1_Click" runat="server" 
               Text="Change Format" />
        </p>
    </form>
</body>
</html>

C#
<%@ Page Language="C#" autoeventwireup="False" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    void Button1_Click(Object sender, EventArgs e) {
        LoginName1.FormatString = "Welcome to our Web site, {0}";
         Button1.Visible = false;
    }

</script>
<html  >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <p>
            <asp:LoginName id="LoginName1" runat="server" 
               FormatString ="Welcome, {0}" />
        </p>
        <p>
            <asp:Button id="Button1" onclick="Button1_Click" runat="server" 
               Text="Change Format" />
        </p>
    </form>
</body>
</html>

System..::.Object
  System.Web.UI..::.Control
    System.Web.UI.WebControls..::.WebControl
      System.Web.UI.WebControls..::.LoginName
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
page will still compile and run      Hongtaoc   |   Edit   |  

"The LoginName control cannot be used outside the "><form> tag on a Web page."

see somebody point out that the page will still compile and run.

Flag as ContentBug
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker