locked
Membership.GetUser - getting username via guid RRS feed

  • Question

  • User-603414224 posted

    Hello - can anyone spot why the below code does not work, i.e. returnValue is always 'Nothing'? 

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      
            Dim ProvideUserKey As String
            Dim returnValue As MembershipUser
            ProvideUserKey = "02B12A3B-E123-123D-9ADF-8B2E81239680"
            returnValue = Membership.GetUser(ProvideUserKey)

    End Sub

    Cheers..Marco

    Friday, September 21, 2007 5:54 PM

Answers

  • User-2074625069 posted

    Are you using a Customer Membership Provider if so you will have to write the code to connection to DB but if you are using the default SQLMembership Provider with the Database Schema generated by ASP this will be done for you.

    Try this:

    Dim membershipUser As MembershipUser = Membership.GetUser(New Guid("02B12A3B-E123-123D-9ADF-8B2E81239680"))

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 22, 2007 6:56 AM

All replies

  • User-2074625069 posted

    Try this:

    Dim providerUserKey As Object = CType("02B12A3B-E123-123D-9ADF-8B2E81239680", Object)
    Dim membershipUser As MembershipUser = Membership.GetUser(providerUserKey)

    Because you are passing a string to the GetUser method is will use this overload:

    Public Shared Function GetUser(ByVal username As String) As System.Web.Security.MembershipUser Member of: System.Web.Security.Membership

    Summary:
    Gets the information from the data source for the specified membership user.

    Parameters:
    username: The name of the user to retrieve.

    you need to be using this overload:

    Public Shared Function GetUser(ByVal providerUserKey As Object) As System.Web.Security.MembershipUser
         Member of: System.Web.Security.Membership
    Summary:
    Gets the information from the data source for the membership user associated with the specified unique identifier.

    Parameters:
    providerUserKey: The unique user identifier from the membership data source for the user.

    let me know how you get on.

     

    Saturday, September 22, 2007 5:37 AM
  • User-603414224 posted

    Hello Scott,

    I can see you have now converted the string into an object so it is in the right format to pass into the getuser overload - thanks for this. When I run the code I get error:

    The provider user key supplied is invalid.  It must be of type System.Guid.
    Parameter name: providerUserKey

    The code on my page is literally as detailed in my original post. I am wondering if I need to make a connection to the DB at any point for the code to work?

    Marco (still a newbie!)

    Saturday, September 22, 2007 6:47 AM
  • User-2074625069 posted

    Are you using a Customer Membership Provider if so you will have to write the code to connection to DB but if you are using the default SQLMembership Provider with the Database Schema generated by ASP this will be done for you.

    Try this:

    Dim membershipUser As MembershipUser = Membership.GetUser(New Guid("02B12A3B-E123-123D-9ADF-8B2E81239680"))

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 22, 2007 6:56 AM
  • User-603414224 posted

     

    Scott, thats done it. Thankyou very much.

    Cheers

    Marco

    Saturday, September 22, 2007 5:30 PM
  • User1869991858 posted

     Why are you providing it with a GUID value?

    Wednesday, December 5, 2007 4:10 PM