Shining Star Services LLC

Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 16

by Nannette Thacker

Our Administration Page.

User Nannette is setup for admin status. If you log in as Nannette, you will see the Admin menu in the left column.



Code In Front

<%@ Page Language="VB" MasterPageFile="~/SSS.Master" 
AutoEventWireup="false" CodeFile="Admin.aspx.vb" 
Inherits="Admin" title="Administration" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" 
Runat="Server">
<%@ MasterType VirtualPath="~/SSS.master" %> 
   <div>
        <asp:Button ID="Button1" runat="server" Text="Display Cookies" /> 
        <asp:Button ID="Button2" runat="server" Text="Delete All Cookies" /> <br />
        <asp:Button ID="Button3" runat="server" Text="Server Vars" /> 
        <asp:Button ID="Button4" runat="server" Text="Roles for User" /> 
        <br />
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label><br />
    </div>
</asp:Content>


Code Behind

Imports Appcookie
Imports System.Web
Imports AdminUtil
Imports ShiningStar.SSSRole

Partial Class Admin
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Me.Load

        If Not User.Identity.IsAuthenticated = True Then
            System.Web.HttpContext.Current.Response.Redirect("~/login/login.aspx", False)
        End If

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Static myCookies As New AppCookie()
        Label1.Text = myCookies.Displaycookies()

    End Sub

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim myAdminUtil As New AdminUtil
        Label1.Text = myAdminUtil.GetServerVars
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Static myCookies As New AppCookie()
        Label1.Text = myCookies.DeleteAllCookiesDisplay()
    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click

        If Roles.IsUserInRole(Page.User.Identity.Name, "Admin") Then
            Dim myroles As String() = Roles.GetRolesForUser(Page.User.Identity.Name)
            Label1.Text = " Roles: "
            For Each role As String In myroles
                Label1.Text += role & "<br />"
            Next
        End If

    End Sub

End Class



AdminUtil class - Just for kicks we allow our admin user to view our server variables, view cookies, delete cookies and view roles. We include an admin class to loop through the server variables.

Imports Microsoft.VisualBasic
Imports System.Web.HttpContext
Imports System.Net


Public Class AdminUtil

    Sub adminutil()
        ' nothing here...
    End Sub

#Region "GetServerVars - display a list of server variables"

    ' http://msdn2.microsoft.com/en-us/library/ms524602.aspx
    ' IIS Server Variables Request.ServerVariables Collection

    ' http://msdn2.microsoft.com/en-us/library/system.web.httprequest.cookies.aspx
    Function GetServerVars() As String
        Dim retString As String = ""
        Dim loop1, loop2 As Integer
        Dim arr1(), arr2() As String
        Dim coll As NameValueCollection

        coll = Current.Request.ServerVariables ' Load ServerVariable collection into NameValueCollection object.
        arr1 = coll.AllKeys ' Put names of all keys into a string array.

        retString = retString & "<table cellpadding=0 cellspacing=0 border=1>"

        For loop1 = 0 To UBound(arr1)
            retString = retString & "<tr><td class=""text1"">"
            retString = retString & arr1(loop1)
            arr2 = coll.GetValues(loop1) ' Get all values under this key.
            retString = retString & "</td><td class=""text1"">"

            For loop2 = 0 To UBound(arr2)
                retString = retString & arr2(loop2) & "<br>"
            Next loop2
            retString = retString & "</td></tr>"
        Next loop1
        retString = retString & "</table>"

        Return retString
    End Function
#End Region


End Class

We are now ready to begin Step 17.

Steps for Creating a Custom Membership Provider and Membership User utilizing a DataSet Table Adapter:

Introduction: Creating a Custom Membership Provider and Membership User utilizing a DataSet Table Adapter.
Step 1: Creating the Project and Folders.
Step 2: Table Data Structure and Web.config for this Tutorial.
Step 3: Creating The DataSet.
Step 4: Creating the Table Adapter Methods for GetUserByLogin, GetUserByUserName, and InsertUser.
Step 5: Creating our Custom MembershipProvider Class.
Step 6: Adding Properties to Our Custom MembershipProvider Class.
Step 7: Creating Our Custom MembershipUser Class.
Step 8: Customizing our MembershipProvider Class.
Step 9: Our Custom RoleProvider Class.
Step 10: Our Master page.
Step 11: Our Cookie Handler class.
Step 12: Our Log In page.
Step 13: Our Register page.
Step 14: Our Log Out page.
Step 15: Our Change Password page.
Step 16: Our Administration page.
Step 17: Loading a Menu Programmatically based on Roles.
Step 18: Our Default page.
Download the ZIP files:
VB: ShiningStarCustomMemberProviderTutorial.zip
© Copyright 1997-2017 Shining Star Services LLC, Nannette Thacker. All Rights Reserved.