Search code examples
asp.net.netmembershiploginview

How to use LoginView control with Membership API Roles


I want to use the roles based authorization in my web site. I have created one role named 'Admin' in the database using default asp.net configuration (in website menu in visual studio). I am using default membership API database. (Created using aspnet_regsql.exe tool).

So I want to use the same roles from the database for LoginView control.

Following is the LoginView Control which I have created.

<asp:LoginView ID="LoginView1" runat="server">
        <LoggedInTemplate>
        <h2>This is the logged in template</h2>
        </LoggedInTemplate>
        <AnonymousTemplate>
        <h2>You are not authenticated</h2>
        </AnonymousTemplate>
        <RoleGroups>
            <asp:RoleGroup Roles="Admin">
                <ContentTemplate>
                    <asp:LinkButton runat="server" ID="lnkBtnCreateUser" 
                        onclick="lnkBtnCreateUser_Click">
                    </asp:LinkButton>
                </ContentTemplate>
            </asp:RoleGroup>
        </RoleGroups>
        </asp:LoginView>

But this control do not display anything for any type of the above mentioned users. Can anybody explain me the exact lacking thing to be implemented in my above code?


Solution

  • Here you can find a quick explanation video

    http://www.youtube.com/watch?v=Yj1Iu2RaEdE

    Cheers