sql provider membership issue RRS feed

  • Question

  • User-1767698477 posted

    I would like to understand why when I make a guid from a query string like below, it works. The userID is accepted in Membership.Getuser(userID)

    userID = New Guid(Request.QueryString("id"))
    'Get information about the user
    Dim userInfo As MembershipUser = Membership.GetUser(userID)
    If userInfo Is Nothing Then
    'Could not find user in database. An altered guid
    Label1.Text = "The user account could not be found in the membership database."
    Exit Sub

    However, when I attempt to do the same thing with a Session variable, it doesn't work.

    How can I get this to work?

    The error says something about a narrowing conversion....

    Dim UserId As Guid = New Guid(Session("Userid"))
    'get the membership user one time
    Dim MUser As MembershipUser = Membership.GetUser(UserId)

    With this code below I get the specified cast is invalid. How is the Session("UserID") stored. Is it a type of uniqueidentifier?  Or is it just a string? How can I tell?

    Tuesday, May 12, 2020 6:06 AM


  • User-1767698477 posted

    I managed to figure this out on my own. The following worked for me.

    Dim uid As String = Session("userID").ToString
    Dim guid As Guid = New Guid(uid)

    I would still like to know why the Session("Userid") has to be converted to a string first.  I took whatever Session turned it into and made a string out of it like the query string example.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 12, 2020 6:12 AM