Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > Custom MembershipProvider retrieve ProviderUserkey from GetUser()?

Thread Tools

Custom MembershipProvider retrieve ProviderUserkey from GetUser()?

Posts: n/a
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 =

' Open the connection and execute the reader
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
cmd = Nothing

Return boolReturn

End Function
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
GetUser.ProviderUserKey gives me System.NullReferenceException Cirene ASP .Net 4 07-07-2008 01:21 AM
problem getting user via ProviderUserKey Jeff ASP .Net 3 05-27-2008 02:07 PM
question about MembershipUser.ProviderUserKey william ASP .Net 2 01-31-2008 07:33 PM
providerUserKey ASP.NET Membershipp Davie ASP .Net 6 09-04-2005 11:02 AM
About custom MembershipProvider =?Utf-8?B?Q2hyaXNUb3JuZw==?= ASP .Net 1 03-09-2005 11:55 AM