473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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
Feb 13 '10 #1
3 2170
Is there anyone that can help me with this?
Feb 13 '10 #2
jhardman
3,406 Expert 2GB
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
Expand|Select|Wrap|Line Numbers
  1. 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("variableName")=value. You can access the value on any page as session("variableName"). Let me know if this helps.

Jared
Feb 18 '10 #3
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.GetUser() IsNot Nothing Then
Useridvalue = Membership.GetUser().ProviderUserKey
End If

Using Myconnection As New SqlConnection
Myconnection.ConnectionString = ConfigurationManager.ConnectionStrings("Connection String").ConnectionString

Dim mycommand As New SqlCommand
mycommand.Connection = Myconnection
mycommand.CommandText = "SELECT Customerid FROM UserData Where UserId = @UserId"
mycommand.Parameters.AddWithValue("@UserId", Useridvalue)

Myconnection.Open()
Dim LUserid As String = mycommand.ExecuteScalar

Myconnection.Close()
Return LUserid
End Using
End Function


And then

Session("customerid") = Helpers.ExecuteScaler

To store the session value.
Feb 18 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Joshua Beall | last post by:
Hi All, What is the best way to use a cookie to remember a logged in user? Would you store the username and password in two separate cookies? Should the password be plain text? Hashed? Not...
3
by: Tom | last post by:
Hi I have a web application using asp.net and c#. User has to login to the application with his username and pwd. However, I do not allow other user uses the same username and pwd to login, i.e....
19
by: Siobhan | last post by:
Hi What is the recommended way to store a user's database credentials across the pages of a web application so that each time the database is accessed the system doesn't have to ask them for their...
11
by: Alan Silver | last post by:
Hello, I am just planning a new ASP.NET site, and wondered about the best way to handle the following common scenario... The site has the option that registered users can log in and will have...
4
by: Nick Gilbert | last post by:
Hi, Is it possible to access the Session of an arbitary user from an aspx page? On an e-commerce site, I am notified of payment success via a callback from the payment server to an ASPX page...
6
by: Morten Snedker | last post by:
A user enters a password. Via stored procedure i lookup that (unique) password. If it is found I save the userID to a Session("userID") for later use. I use no other saved variables than this one....
2
by: underground | last post by:
Hi, everyone I've been trying to figure out a way for a user to update there information. I'm using sections to identify the specific user..Here is the form <? include("include/session.php");...
0
by: preeti13 | last post by:
Hi friends i am here again with my probelm. i have one login page when first login on the page it is checking the active directory user exist or not if user exist then go the next page all i nee to...
9
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
1
by: jerrydigital | last post by:
Hello, I am having trouble getting unique user information on my account page. Currently, once the user logs in, it will only display "Welcome...(then the same name pops up no matter who logs in)"....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.