Welcome page : LoginStatus « Login Security « ASP.Net

ASP.Net
1. ADO.net Database
2. Ajax
3. Asp Control
4. Collections
5. Components
6. Data Binding
7. Development
8. File Directory
9. HTML Control
10. Language Basics
11. Login Security
12. Mobile Control
13. Network
14. Page
15. Request
16. Response
17. Server
18. Session Cookie
19. Sitemap
20. Theme Style
21. User Control and Master Page
22. Validation by Control
23. Validation by Function
24. WebPart
25. WPF
26. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.Net » Login Security » LoginStatus 
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.