I'm not an expert programmer in any way shape or form but I'm working on my next project and need some assistance. We have an existing site that is up and been running for a couple years and needs an uplift to asp .net 2.0. All our data is in a SQL 2005 db and is accessed by 3 groups, administrators, techs and clients. Admin see all data and all functions, Techs only see their calls and clients only see their data but some clients have 20 users. Our SQL db uses a field named accounID to tied multiple accounts together. On our old site once a user logged on a session was created (stored in a 2nd db) that tied the users name to their accountID. Then we can use the session accountID to pull from the db and the customer only see's what we want them to see.In ASP .Net 2.0 I have looked at using cookies, profiles and sessions to perform the same function. For now I want to stick with sessions. Creating logins, create new users, ect is easing enough with the built in controls in .net but for the life of me I can figure out how to tie the logged in user with a session to associate the accountID with that user. Once I get past this one step the rest will be a breeze. I created a dummy page using a fixed session that works but of course this needs to be dynamic not fixed. The old site only uses one page for all three account types with many clients and I would like to keep it that way. Here's the code on the code behind page using page load to create the static session. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load, LoginName1.DataBinding
Dim firstName As String = "DSS"
Session("UserName") = firstName
mylabel.Text = Session("UserName")
End SubAs the page is loaded DSS becomes the session "username" and the data grid on the page uses the variable "dss" in the qry and pulls DSS data. I realize you all probably need more info and I appreciate the time.Thanks
![]() |
0 |
![]() |
I possible problem that I noticed is that you do not have the code enclosed in:
If Not Page.IsPostBack Then
'Code goes here
End IfHave that code run on every postback could be causing some problems.
Mark this post as the "Answer" if it was the answer.
![]() |
0 |
![]() |
hi,
try to like this,
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
if Not Page.IsPostBack then
Session("UserName") = firstName
mylabel.Text = Session("UserName")
end ifEnd Sub
The Page_Load subroutine runs EVERY time the page is loaded. If you want to execute the code in the Page_Load subroutine only the FIRST time the page is loaded, you can use the Page.IsPostBack property. If the Page.IsPostBack property is false, the page is loaded for the first time, if it is true, the page is posted back to the server.
![]() |
0 |
![]() |
Thanks for the response as I said I'm a newb the .net here.I do know that using the code you gave will generate and exception because firstname is not declared. What I need to do is somehow create a session from data stored in the ASP_user table from the accountID associated with the user. accoutID is a field I added to the asp_user table. Bob logs in using the ASP.net login control (which works fine) is then redirected to the client page at the same time a session is created that looks at Bobs data in the db and reads his accountID (in asp_user table) that in turn is used in a gridview to pulls bobs data.
The whole point is to not pass parameters via a URL which is not secure.Make since?
![]() |
0 |
![]() |
After looking at your post again, I noticed that you are handling login.databound in your page_load. Why don't you set the session in the actual login event? Another question: Why not just you my.user.name as opposed to storing it in session?
Mark this post as the "Answer" if it was the answer.
![]() |
0 |
![]() |
Well because I'm learning and don't know the proper way. login.databound worked and it was a start. I was just happy to see the page post data. I'm assuming my.user.name is the command to read the user name from the login control? That's what I was looking for in the first place. Now all I got's to do if figure out how to use it. Is there a goob book that list all the .Net commands and their function like session, my.user.name ect?
**edit**
Well I got the first have of the issue resolve, Bob logs in and pulls Bob's data, John logs in and pulls Johns data:
Protected
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
mylabel.Text = My.User.Name
End SubBut Tell me If my logic is correct.
Bob logs in with UID Bob so does Lucy and Mike and they all have the accountID = DSS
So the logic would be
IF bob = my.user.name
THEN GET bobs accountID from asp_user tbl "accountID"
with SQLREAD pass "accountID" to mylabel.text
The run the qry.
Thanks
![]() |
0 |
![]() |