Last post May 12, 2020 06:12 AM by sking
May 12, 2020 06:06 AM|sking|LINK
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."
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?
May 12, 2020 06:12 AM|sking|LINK
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.