Welcome page : LoginStatus « Login Security « ASP.Net






Welcome page


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Welcome_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:LoginStatus ID="LoginStatus1" runat="server" />
        <asp:LoginView ID="LoginView1" runat="server">
            <LoggedInTemplate>
                Welcome
                <asp:LoginName ID="LoginName1" runat="server" />
                <br />
                <asp:HyperLink 
                    ID="hlChangePW" 
                    NavigateUrl="ChangePW.aspx" 
                    runat="server">Change Password
                 </asp:HyperLink>
                 &nbsp;
                 <asp:HyperLink 
                    ID="hlCreateUser" 
                    NavigateUrl="CreateAccount.aspx" 
                    runat="server">Create User
                 </asp:HyperLink>
                <br />
                <asp:HyperLink 
                    ID="hlManageRoles" 
                    NavigateUrl="ManageRoles.aspx" 
                    runat="server">Manage Roles
                </asp:HyperLink> <br />
            </LoggedInTemplate>
            <AnonymousTemplate>
                You are not logged in. 
            </AnonymousTemplate>
         </asp:LoginView>
        <asp:HyperLink 
            ID="hlProfile" 
            NavigateUrl="ProfileInfo.aspx" 
            runat="server">Profile Information
        </asp:HyperLink>
        <br />
        <asp:ListBox  ID="lbBooks" runat="server" />
         <asp:Panel ID="pnlInfo" Runat="server" Visible="False">
           <asp:Label ID="lblFullName" Runat="server" Text="Full name unknown"/>
           <asp:Label ID="lblPhone" Runat="server" Text="Phone number unknown"/>
           <asp:Label ID="lblBirthDate" Runat="server" Text="Birthdate  unknown"/>
         </asp:Panel>
    </div>
    </form>
</body>
</html>

File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Welcome_aspx : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    if ( ! Profile.IsAnonymous )
    {
      this.pnlInfo.Visible = true;
      this.lblFullName.Text = Profile.firstName + " " + Profile.lastName;
      this.lblPhone.Text = Profile.phoneNumber;
      this.lblBirthDate.Text = Profile.birthDate.ToShortDateString();

      this.lbBooks.Items.Clear();
    }
    else
    {
      this.pnlInfo.Visible = false;
    }
    if (Profile.MyFlag != null)
    {
      foreach (string bookName in Profile.MyFlag)
      {
        this.lbBooks.Items.Add(bookName);
      }
    }
  }
}

File: Web.Config

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer" connectionString="data source=.\SqlExpress;Integrated Security=SSPI;Initial Catalog=aspnetdb"/>
  </connectionStrings>
  <system.web>
    <anonymousIdentification enabled="true" />
    <authentication mode="Forms"/>
    <membership defaultProvider="AspNetSqlMembershipProvider"/>
    <roleManager enabled="True" defaultProvider="AspNetSqlRoleProvider"/>
    <compilation debug="true"/>
    <profile enabled="True" defaultProvider="AspNetSqlProfileProvider">
      <properties>
        <add name="lastName" />
        <add name="firstName" />
        <add name="phoneNumber" />
        <add name="birthDate" type="System.DateTime"/>
        <add name="MyFlag" allowAnonymous="true" 
         type="System.Collections.Specialized.StringCollection"  />
      </properties>
    </profile>
  </system.web>
</configuration>

 








Related examples in the same category

1.Login and logout features of the LoginStatus control
2.Displaying the username of the authenticated user
3.outputs the name of the currently logged user as authenticated by the ASP.NET application