Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 8th, 2007, 09:45 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Table definition for CreateUserWizard

Hi,

I'm very very new to ASP.NET,

How can I define which table in the database for my createuserwizard to go to ? instead of using the default aspnet users table.

Can anynone help me please ?

  #2 (permalink)  
Old July 9th, 2007, 11:47 AM
Friend of Wrox
 
Join Date: Feb 2006
Location: , , USA.
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You're going to need to implement a custom membership provider.
  #3 (permalink)  
Old July 9th, 2007, 06:49 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx .. can you eleborate more on that .. you know .. since i'm a newbie :D

  #4 (permalink)  
Old July 25th, 2007, 09:57 AM
Friend of Wrox
 
Join Date: Feb 2006
Location: , , USA.
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sure, basically when you use those default asp.net membership and role tables in sql server, the code you are really using is the default sql server membership provider. Since it's the default you don't have to write any code other than configuring in your web.config that you are using it.

If you want to use your own database objects, obviously the default sql membership provider would have no idea what your table and field names are, what your stored procedure names and arguments are, etc. So you have to write a custom membership provider that inherits from System.Web.Security.Membership provider, and implement all of the desired functionalities that it provides.

For example, obviously one of the key functionalities it provides is authenticating a user. You have to override a function named ValidateUser. In there you provide the custom code you would use to validate a user with whatever is stored in your database.

Code:
Imports Microsoft.VisualBasic
Imports System.Web.Security
Imports System.Data.SqlClient
Imports System.Configuration

Public Class CustomMembershipProvider
    Inherits System.Web.Security.MembershipProvider

    Public Overrides Property ApplicationName() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Overrides Function ChangePassword(ByVal username As String, ByVal oldPassword As String, ByVal newPassword As String) As Boolean

    End Function

    Public Overrides Function ChangePasswordQuestionAndAnswer(ByVal username As String, ByVal password As String, ByVal newPasswordQuestion As String, ByVal newPasswordAnswer As String) As Boolean

    End Function

    Public Overrides Function CreateUser(ByVal username As String, ByVal password As String, ByVal email As String, ByVal passwordQuestion As String, ByVal passwordAnswer As String, ByVal isApproved As Boolean, ByVal providerUserKey As Object, ByRef status As System.Web.Security.MembershipCreateStatus) As System.Web.Security.MembershipUser

    End Function

    Public Overrides Function DeleteUser(ByVal username As String, ByVal deleteAllRelatedData As Boolean) As Boolean

    End Function

    Public Overrides ReadOnly Property EnablePasswordReset() As Boolean
        Get

        End Get
    End Property

    Public Overrides ReadOnly Property EnablePasswordRetrieval() As Boolean
        Get

        End Get
    End Property

    Public Overrides Function FindUsersByEmail(ByVal emailToMatch As String, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As System.Web.Security.MembershipUserCollection

    End Function

    Public Overrides Function FindUsersByName(ByVal usernameToMatch As String, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As System.Web.Security.MembershipUserCollection

    End Function

    Public Overrides Function GetAllUsers(ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As System.Web.Security.MembershipUserCollection

    End Function

    Public Overrides Function GetNumberOfUsersOnline() As Integer

    End Function

    Public Overrides Function GetPassword(ByVal username As String, ByVal answer As String) As String

    End Function

    Public Overloads Overrides Function GetUser(ByVal providerUserKey As Object, ByVal userIsOnline As Boolean) As System.Web.Security.MembershipUser

    End Function

    Public Overloads Overrides Function GetUser(ByVal username As String, ByVal userIsOnline As Boolean) As System.Web.Security.MembershipUser

    End Function

    Public Overrides Function GetUserNameByEmail(ByVal email As String) As String

    End Function

    Public Overrides ReadOnly Property MaxInvalidPasswordAttempts() As Integer
        Get

        End Get
    End Property

    Public Overrides ReadOnly Property MinRequiredNonAlphanumericCharacters() As Integer
        Get

        End Get
    End Property

    Public Overrides ReadOnly Property MinRequiredPasswordLength() As Integer
        Get

        End Get
    End Property

    Public Overrides ReadOnly Property PasswordAttemptWindow() As Integer
        Get

        End Get
    End Property

    Public Overrides ReadOnly Property PasswordFormat() As System.Web.Security.MembershipPasswordFormat
        Get

        End Get
    End Property

    Public Overrides ReadOnly Property PasswordStrengthRegularExpression() As String
        Get

        End Get
    End Property

    Public Overrides ReadOnly Property RequiresQuestionAndAnswer() As Boolean
        Get

        End Get
    End Property

    Public Overrides ReadOnly Property RequiresUniqueEmail() As Boolean
        Get

        End Get
    End Property

    Public Overrides Function ResetPassword(ByVal username As String, ByVal answer As String) As String

    End Function

    Public Overrides Function UnlockUser(ByVal userName As String) As Boolean

    End Function

    Public Overrides Sub UpdateUser(ByVal user As System.Web.Security.MembershipUser)

    End Sub

    Public Overrides Function ValidateUser(ByVal username As String, ByVal password As String) As Boolean
        Dim sqlCon As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("DbConnectionString").ToString())
        Dim sqlCmd As SqlCommand = New SqlCommand( _
            "SELECT 1 " & _
            "FROM User " & _
            "WHERE userId = @userName AND LEN(userId) > 0 " & _
            "AND password = @password ", sqlCon)
        sqlCmd.Parameters.Add(New SqlParameter("@userName", System.Data.SqlDbType.VarChar))
        sqlCmd.Parameters("@userName").Value = username
        sqlCmd.Parameters.Add(New SqlParameter("@password", System.Data.SqlDbType.VarChar))
        sqlCmd.Parameters("@password").Value = password
        sqlCon.Open()
        Dim returnVal As Boolean = False
        If CStr(sqlCmd.ExecuteScalar()) = "1" Then
            returnVal = True
        End If
        sqlCon.Close()
        Return returnVal
    End Function

End Class
When you inherit your class from System.Web.Security.MembershipProvider, Visual Studio will automatically insert all of the properties and function signatures you can implement, and it's your job to implement the ones you want. I provided an example of implementing the ValidateUser which is obviously the most important. Good luck.


Similar Threads
Thread Thread Starter Forum Replies Last Post
'Table' does not contain a definition for 'BorderS AccessAasif@aol.com C# 2005 1 September 13th, 2008 03:08 AM
CreateUserWizard secondary table Return_Value jonnyO ADO.NET 0 November 16th, 2006 01:41 AM
Find definition of a type ag19702004 Visual Studio 2005 0 October 2nd, 2006 05:21 PM
Definition Little Shell VB.NET 2002/2003 Basics 3 October 12th, 2005 07:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.