stevebramall
06-23-2007, 02:46 AM
Hi again
please could you help?
I am trying to get an aspx page to retreive the userid of the currently logged in user of my site. I have used
Partial Class MasterPage
Inherits System.Web.UI.MasterPage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
useridvalue.Text = Membership.GetUser().ProviderUserKey.ToString
End Sub
this is so that I can filter the objects only to show their own collections.
This works fine and displays the userID - still in test mode - i'll make it non visible for live version.
Howver, when user logs out I get an error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 8: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Line 9:
Line 10: useridvalue.Text = Membership.GetUser().ProviderUserKey.ToString
Line 11:
Line 12:
which I think is becuase the above cannot contain a null.
I have tried to establish an condition -
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
useridvalue.Text = Membership.GetUser().ProviderUserKey.ToString
' Dim userInfo As MembershipUser = Membership.GetUser(Login1.UserName)
' If userInfo Is Nothing Then
'useridvalue.Text = "no-one is logged in"
'Else
'useridvalue.Text = Membership.GetUser().ProviderName.ToString
'End If
End Sub
but this does not work becasue it always shows "no-one logged in " even why they are. It does, however, work in the sense that it does not crash the page.
Help- Please could you give me some advice on how to use the memebrship.getuser working so that the page knows the userId when logged on but would not throw an exception is no-one is in.
many thanks
As you can see from previous posts - i'm still relatively knew to programming
steve
please could you help?
I am trying to get an aspx page to retreive the userid of the currently logged in user of my site. I have used
Partial Class MasterPage
Inherits System.Web.UI.MasterPage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
useridvalue.Text = Membership.GetUser().ProviderUserKey.ToString
End Sub
this is so that I can filter the objects only to show their own collections.
This works fine and displays the userID - still in test mode - i'll make it non visible for live version.
Howver, when user logs out I get an error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 8: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Line 9:
Line 10: useridvalue.Text = Membership.GetUser().ProviderUserKey.ToString
Line 11:
Line 12:
which I think is becuase the above cannot contain a null.
I have tried to establish an condition -
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
useridvalue.Text = Membership.GetUser().ProviderUserKey.ToString
' Dim userInfo As MembershipUser = Membership.GetUser(Login1.UserName)
' If userInfo Is Nothing Then
'useridvalue.Text = "no-one is logged in"
'Else
'useridvalue.Text = Membership.GetUser().ProviderName.ToString
'End If
End Sub
but this does not work becasue it always shows "no-one logged in " even why they are. It does, however, work in the sense that it does not crash the page.
Help- Please could you give me some advice on how to use the memebrship.getuser working so that the page knows the userId when logged on but would not throw an exception is no-one is in.
many thanks
As you can see from previous posts - i'm still relatively knew to programming
steve