Need help with Login Control

Discussion in 'ASP .Net Security' started by Learner, Jul 20, 2006.

  1. Learner

    Learner Guest

    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
     
    Learner, Jul 20, 2006
    #1
    1. Advertising

  2. Learner

    Ron Guest

    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


    "Learner" wrote:

    > 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
    >
    >
     
    Ron, Jul 21, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ike2010
    Replies:
    0
    Views:
    675
    ike2010
    Nov 15, 2005
  2. ad

    Can login with Login Control

    ad, Aug 28, 2006, in forum: ASP .Net
    Replies:
    9
    Views:
    952
    Tim_Mac
    Aug 31, 2006
  3. Sasquatch
    Replies:
    2
    Views:
    1,320
    Sasquatch
    Oct 3, 2006
  4. Replies:
    0
    Views:
    371
  5. Jack
    Replies:
    1
    Views:
    729
Loading...

Share This Page