Custom MembershipProvider retrieve ProviderUserkey from GetUser()?

Discussion in 'ASP .Net Security' started by Rick, Oct 11, 2005.

  1. Rick

    Rick Guest

    I have gotten my Custom MembershipProvider working with my own SQL Server DB.
    The application authenticates a particular company with ValidateUser and I
    want to then call up the Company record from my SQL Server DB. I need to
    retrieve the Primary Key (CompanyID) from the DB and use that to open the
    correct SqlDataSource. I need to figure out if it's possible to do this with
    MemebershipUser without having to set up a Personalization Provider. It seems
    like there are two options, one is to retrieve the CompanyID from
    ValidateUser and stuff it into a Session Variable. The other would be to set
    up GetUser to pull the CompanyID in as the ProviderUserKey. I presume its
    better to use GetUser but I don't know how to write the GetUser code. Here's
    my ValidateUser


    Public Overrides Function ValidateUser(ByVal userName As String, ByVal
    password As String) As Boolean

    Dim boolReturn As Boolean = False
    Dim connString As String
    Dim CompanyID As Integer
    connString = "Server=server;User ID=UID;password=pw;Database=db"
    Dim commString As String
    commString = "SELECT CompanyID from Company WHERE Userid =
    @UserID and Password = @Password"
    Dim conn As SqlConnection = New SqlConnection(connString)
    Dim cmd As SqlCommand = New SqlCommand(commString, conn)
    cmd.Parameters.Add("@UserID", SqlDbType.VarChar).Value = userName
    cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value =
    password

    ' Open the connection and execute the reader
    conn.Open()
    Dim reader As SqlDataReader
    reader = cmd.ExecuteReader()

    ' Did we find a user?
    If reader.Read() Then
    boolReturn = True
    CompanyID = (reader("CompanyID"))

    'CompanySession =
    End If

    ' Close connections
    reader.Close()
    conn.Close()
    cmd = Nothing

    Return boolReturn

    End Function
    --
    Rick
     
    Rick, Oct 11, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2hyaXNUb3JuZw==?=

    About custom MembershipProvider

    =?Utf-8?B?Q2hyaXNUb3JuZw==?=, Mar 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    483
    Paul Glavich [MVP ASP.NET]
    Mar 9, 2005
  2. Davie
    Replies:
    6
    Views:
    13,113
    Davie
    Sep 4, 2005
  3. william
    Replies:
    2
    Views:
    881
    william
    Jan 31, 2008
  4. Jeff
    Replies:
    3
    Views:
    561
  5. Cirene
    Replies:
    4
    Views:
    1,173
    Tanzim Saqib
    Jul 7, 2008
Loading...

Share This Page