ASP.Net 2.0 LoginView Control

by top54u.com 19 May, 2008
Spotlight.....

LoginView provides the functionality to create different views for the users of different Roles. LoginView control consists of 3 different templates:

  1. AnonymousTemplate

  2. LoggedInTemplate

  3. RoleGroups

 

AnonymousTemplate

AnonymousTemplate of LoginView control can be used to display the default view of the LoginView that can be viewed by unauthenticated, guest or anonymous user. You can place the link to login page or login control inside the AnonymousTemplate. LoginView Control displays the content and controls of AnonymousTemplate if there is no user logged in.

 

LoggedInTemplate

LoginView Control detects the login status of the user, if membership provider gets the status as authenticated user has logged in then it displays the view provided by the LoggedInTemplate. You can display the LoginStatus, LoginName of the current logged in user in LoggedInTemplate.

 

RoleGroups

RoleGroups Template consists of collection of templates for different roles stored in the default aspnetdb database that provides the feature of membership as well as roles management. RoleGroups is further divided into asp:RoleGroup that has an attribute to set the Roles to associate the view with any particular role. asp:RoleGroup consists of ContentTemplate that accommodates the set of controls placed inside it to generate the role associated view.

 

Note: When RoleGroups template is used in LoginView Control then it automatically detects the role of logged in user and displays the role associated view for that role based user. If the current logged in user has not been assigned any role then LoginView displays the LoggedInTemplate view for that user.

 

Controls placed inside the LoginView control cannot be accessed directly in the code. You have to use FindControl method to find the control placed inside the LoginView control e.g.: LoginView1.FindControl(“controlID”)

 

Sample Code for LoginView Control

Following code shows the different views created using all 3 template styles of LoginView Control of ASP.Net 2.0:

[code:html]
        <asp:LoginView ID="LoginView1" runat="server">
            <RoleGroups>
                <asp:RoleGroup Roles="admin">
                    <ContentTemplate>
                        hello admin<br />
                        <asp:LoginName ID="LoginName1" runat="server" />
                    </ContentTemplate>
                </asp:RoleGroup>
                <asp:RoleGroup Roles="user">
                    <ContentTemplate>
                        hello user<br />
                        <asp:LoginName ID="LoginName1" runat="server" />
                    </ContentTemplate>
                </asp:RoleGroup>
            </RoleGroups>
            <LoggedInTemplate>
            You are logged in as: <asp:LoginName ID="LoginName1" runat="server" />
            </LoggedInTemplate>
            <AnonymousTemplate>
            You are not logged in. Please Login...
            </AnonymousTemplate>
        </asp:LoginView>
[/code]

Spotlight.....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , , , ,

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/23/2008 8:46:35 PM

OUR SPONSORS[+ advertise here]
related videos.....
recent posts.....
top54u ezines.....