 |
| ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 3rd, 2010, 09:52 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Can't Read User.ProviderUserKey
Help please. Thank you.
I get this statement in the watch window:
Because this evaluation could cause side effects, it will not be executed until enabled by user.
Membership.GetUser().UserName does show the name of the logged in user
Code:
Session("loggedinusername") = Membership.GetUser().UserName
Dim User As MembershipUser = Membership.GetUser()
Dim UserKey As GUID = User.ProviderUserKey
|
|

May 3rd, 2010, 10:09 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
GetUser is a method, so the watch window doesn't execute it for you automatically. You have to manually execute / enable it.
Cheers,
Imar
|
|

May 3rd, 2010, 10:23 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
The problem is that it's empty in my code
When I breakpoint in my code the value UserKey is empty
There is definitely a value in the Membership DB
Last edited by sg48; May 3rd, 2010 at 10:25 AM..
|
|

May 3rd, 2010, 10:37 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
But what happens when you manually update the value by clicking the refresh icon in the watch window? I thought that's what you meant with "Because this evaluation could cause side effects, it will not be executed until enabled by user."
Cheers,
Imar
|
|

May 3rd, 2010, 10:42 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
The value in the watch window shows as Empty when I click the + sign
I think the watch window is not relevant.
In my code when I manually examine the ProviderUserKey it is empty.
My query that uses it as a parameter is failing because of this.
There is a value in the Membership DB and there is a logged in user
|
|

May 3rd, 2010, 10:55 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
This is not about the plus sign, but about the Refresh icon near that message you posted. My guess is that the code is OK, but that the Watch window just doesn't execute it.
What happens when you watch:
Membership,GetUser("UserNameOfUserThatIsLoggdIn")
In other words, how can you be sure there is a logged in user?
Imar
|
|

May 3rd, 2010, 11:09 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Because
Session("loggedinusername") = Membership.GetUser().UserName
Shows the name of the logged in user
|
|

May 3rd, 2010, 11:28 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Then it has to have a ProviderUserKey as well.
Are you're interpreting the value in the wacth window correctly? Your posts feel a bit crumpy and you're not really supplying a whole lot of information which makes it kind of unattractive to dig into this real deep with you, but my guess is that what you see in the watch window is not what you think you are seeing. Another guess is that entering
Membership.GetUser().ProviderUserKey.ToString() will shed some light on this.
Cheers,
Imar
|
|

May 3rd, 2010, 11:44 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
I do appreciate your help.
I put in an instruction to convert the ProviderUserKey to a string as you suggested and it does show a value. My code is failing when I am filling my dataset.
Code:
ProtectedSub InitSessionVariables()
Session("loggedinusername") = Membership.GetUser().UserName
Dim User As MembershipUser = Membership.GetUser()
Dim UserKey As GUID = User.ProviderUserKey
Dim a AsString = Membership.GetUser().ProviderUserKey.ToString()
Dim Conn AsNew SqlConnection(dsDeals.ConnectionString)
'******************************************
Dim dataSet1 AsNew DataSet()
Dim adapter1 As SqlDataAdapter
Dim CmdGetPersonData AsNew SqlCommand("procGetPersonByUserIDSelect", Conn)
CmdGetPersonData.CommandType = Data.CommandType.StoredProcedure
Dim useridparam AsNew SqlParameter("@userid", SqlDbType.UniqueIdentifier)
useridparam.Value = UserKey
Dim PersonID AsInteger
Dim FName AsString
Dim LName AsString
Conn.Open()
adapter1 = New SqlDataAdapter(CmdGetPersonData)
Try
adapter1.Fill(dataSet1)
My stored procedure is shown below
Code:
ALTER PROCEDURE dbo.procGetPersonByUserIDSelect
(
@userid UniqueIdentifier
)
AS
SELECT PersonID, FName, LName
FROM tblPerson WHERE userid=@userid
RETURN
|
|

May 3rd, 2010, 11:55 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
I removed my tRy Catch and am getting following error now
Procedure or function 'procGetPersonByUserIDSelect' expects parameter '@userid', which was not supplied.
|
|
 |