Need help with Login Control

L

Learner

Hello,

I am trying to get the UserID from the aspnet_users from aspnetdb
database with the below code snippet.



Protected

Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Login1.LoggedIn

Dim UserID As String = String.Empty

Dim ManufacturerID As Integer
UserID =
Membership.GetUser(Page.User.Identity.Name).ProviderUserKey.ToString


Dim BL As New GroundingBL
ManufacturerID = BL.GetManufacturerIDFromUsers(UserID)


End Sub


As you see I am using Login1_LoggedIn event, to me, that means the user
is already logged in. But for some reason the value of
page.User.Identity.Name is empyt ("") when I debug. Am I using the
wrong event here? When I debug all through I get the below error

*************************************************************

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_drkvx8xw"
StackTrace:
at UnSecured_MainLogin.Login1_LoggedIn(Object sender, EventArgs
e) in
D:\VSProjects\GroundingDemo\GroundingDemo\UnSecured\MainLogin.aspx.vb:line
16
at System.Web.UI.WebControls.Login.OnLoggedIn(EventArgs e)
at System.Web.UI.WebControls.Login.AttemptLogin()
at System.Web.UI.WebControls.Login.OnBubbleEvent(Object source,
EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source,
EventArgs args)
at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs
e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


****************************************************************

I need the UserID value and should put in a session variable and should
be used to pull other data values in our database based on this UserID
value.

Could some one please help me here and suggest me the right event that
fires off after user completely logged in.



Thanks

-L
 
R

Ron

For on your ManufactureID is an Int value.
And the UserId of the aspnet_Users table is a Guid();

But to get that value form the table you have to do the following.

Try this.

Guid userID = new Guid();
userID = (Guid)Membership.GetUser(_userName).ProviderUserKey;


string someId = userID.ToString();

Of course this is in C# so you will have to convert to VB

Hope this helps.
Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top