Click here to Skip to main content
15,891,253 members
Articles / Web Development / ASP.NET

Developing custom ASP.NET Membership and Role providers reading users from custom section in the web.config

Rate me:
Please Sign up or sign in to vote.
4.76/5 (33 votes)
7 Aug 2008CPOL8 min read 127.5K   2.1K   74  
In this article, we will be developing custom Membership and Role providers which will read user credentials from a custom configuration section in the web.config file.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Test page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:LoginView ID="LoginView1" runat="server">
            <LoggedInTemplate>
                Hello <asp:LoginName ID="LoginName1" runat="server" />. If you want you may
                <asp:LoginStatus ID="LoginStatus1" runat="server" /> now.
            </LoggedInTemplate>
            <AnonymousTemplate>
                this should not be seen by anyone since only loged in users are allowed (see the
                web config file)
            </AnonymousTemplate>
        </asp:LoginView>
        <asp:LoginView ID="LoginView2" runat="server">
            <RoleGroups>
                <asp:RoleGroup Roles="Administrator">
                    <ContentTemplate>
                        <div style="clear:both;">The following button is only visible to admins 
                         <asp:Button ID="cmdAdminButton" runat="server" Text="This is an admin button" OnClick="cmdAdminButton_Click" /></div>
                    </ContentTemplate>
                </asp:RoleGroup>
                <asp:RoleGroup Roles="User"><ContentTemplate>
                  <div style="clear:both;">The following button is only visible to users with role User
                <asp:Button ID="cmdShowAMessage" runat="server" Text="Show me a message" OnClick="cmdShowAMessage_Click" /></div>
                </ContentTemplate></asp:RoleGroup>
            </RoleGroups>
        </asp:LoginView>
        <asp:Label ID="fldRoles" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Greece Greece
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions