• http://www.techneurons.com/career/
  • experienced programming consultants for hire !!!

    Contact Now

    ASP.NET Articles

    KB: ASP.NET Login based controls

    FRIDAY, FEBRUARY 26, 2010

    This articles explains how to use the ASP.NET Membership and Roles features to control various parts of the page according the logged in user. By using these features, we can create templates for anonymous users, logged-in users, role-based templates, and also login and online status. Most simple case would be to display Login link when no user is logged in, and the same would turn as Logout link when a user is logged on from that browser.

    LoginName control

    The simplest control among the ASP.NET membership controls is the LoginName control. This control simply replaces the name of the logged in user in it's place. This is identical to the User.Identity.Name property available from the Page class. To display a Welcome message on the top of the web application for logged-in users, the following snippet can be used without any additional code.

      
        Welcome, <asp:LoginName runat="server" ID="LoginName1" />
    

    LoginStatus Control

    LoginStatus is a simple membership online status control which shows a Login link button when the site access is anonymous and a Logout link button when a user is logged in. This control also allows you to set the texts or images for the Login and Logout buttons.

     
        <asp:LoginStatus ID="LoginStatus4" runat="server" />
        <asp:LoginStatus ID="LoginStatus5" runat="server" LoginText="Sign In" LogoutText="Sign Out" /<>
        <asp:LoginStatus ID="LoginStatus6" runat="server" LoginImageUrl="/images/login.gif" LogoutImageUrl="/images/logout.gif" />
    

    LoginView Control

    LoginView is an advanced template-editable control which allows to display contents depending on the logged in user and his roles.  This control would be really helpful when you write Content Management System applications, where you need to embed edit links and controls which should be visible only for administrators and moderators. This will make the website look normal for general or public users, and with extra controls for a special user like a moderator or administrator.

     
            <asp:LoginView runat="server" ID="LoginView1">
                <AnonymousTemplate>
                    This will appear for anonymous users, i.e., before without logging in.
                </AnonymousTemplate>
                <LoggedInTemplate>
                    This content will appear only for logged in users, irrespective of the roles.
                </LoggedInTemplate>
                <RoleGroups>
                    <asp:RoleGroup Roles="Administrator">
                        This content will appear for users of role Administrators
                    </asp:RoleGroup>
                    <asp:RoleGroup Roles="Moderator">
                        This content will appear for users of role Moderator
                    </asp:RoleGroup>
                </RoleGroups>
            </asp:LoginView>
    
    

    In the above snippet, there can be one or more content templates depending on the purpose.

    ConsultSarath - We provide end to end outsourcing solutions for .net programming requirements- you can hire programmer for hourly rates, for monthly commitments, for short term projects, for long term projects, Contact to know our hourly rates for programmer in India. ConsultSarath - We provide end to end outsourcing solutions for php programming requirements- you can hire programmer for hourly rates, for monthly commitments, for short term projects, for long term projects, Contact to know our hourly rates for programmer in India. ConsultSarath - We provide end to end outsourcing solutions for python programming requirements- you can hire programmer for hourly rates, for monthly commitments, for short term projects, for long term projects, Contact to know our hourly rates for programmer in India.

    Other Popular Articles
    We are experts in Cloud Computing Technologies. We can assist you to build high scalable business applications using Amazon Web Services (Amazon EC2, Amazon S3, Amazon SES, SNS, CloudFront), Windows Azure Platforms - Windows Azure and SQL Server Azure, Google App Engine using Python and Django Framework. We are Expert Programming Consultants available at affordable rates per hour. We work on several technologies - .NET, Python, Google App Engine, PHP, Windows Azure, Amazon Web Services ...