How to add additional user information to session on login

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Michaeloco
    New Member
    • Feb 2010
    • 3

    How to add additional user information to session on login

    Hello,

    I am using the built in membership provider with vwd. On login i want to add a custom session object from a UserData table in my sql database to session on login to be used on all pages of my application. I have looked all over for this and cant find a good answer to get an idea on how this works.

    All i want to do is add Customerid from my UserData table to the specific user based on Userid of the currently logged on user and then add that to session so i can call on it anytime.

    Can anyone help? Been looking for an answer for 2 weeks now.

    Regards
  • Michaeloco
    New Member
    • Feb 2010
    • 3

    #2
    Is there anyone that can help me with this?

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      Sorry for the long delay, I have been unavailable for a while. this is very easy if you can get to the data, all you have to do is
      Code:
      session("customerID")=numberFromDB
      session variables are just about the easiest thing to work with, you can not do anything to declare the variable beforehand, you just state the obvious: session("variab leName")=value. You can access the value on any page as session("variab leName"). Let me know if this helps.

      Jared

      Comment

      • Michaeloco
        New Member
        • Feb 2010
        • 3

        #4
        Thankyou for your reply, What i ended up doing is pulling the info out of the DB with a class helper on page load for my start page, im not sure if this is the "right" way of doing it but it works. It just seems like a long winded way of doing it. Im new to this so as i said im not sure if this is right so dont kill me over code :P but it works.

        Class.vb code

        Public Shared Function ExecuteScalar() As Object
        Dim Useridvalue As Guid
        If Membership.GetU ser() IsNot Nothing Then
        Useridvalue = Membership.GetU ser().ProviderU serKey
        End If

        Using Myconnection As New SqlConnection
        Myconnection.Co nnectionString = ConfigurationMa nager.Connectio nStrings("Conne ctionString").C onnectionString

        Dim mycommand As New SqlCommand
        mycommand.Conne ction = Myconnection
        mycommand.Comma ndText = "SELECT Customerid FROM UserData Where UserId = @UserId"
        mycommand.Param eters.AddWithVa lue("@UserId", Useridvalue)

        Myconnection.Op en()
        Dim LUserid As String = mycommand.Execu teScalar

        Myconnection.Cl ose()
        Return LUserid
        End Using
        End Function


        And then

        Session("custom erid") = Helpers.Execute Scaler

        To store the session value.

        Comment

        Working...