Showing posts with label session. Show all posts
Showing posts with label session. Show all posts

Thursday, March 22, 2012

Newbie in ASP(not advanced by any means)

Hey everyone, I'm trying to use Session Variables for the first time. I just have a couple of questions, when I debub(Step Thru) the code--is there a way to tell what value they hold?

Secondly, without makin a class is the following code going to do it's purpose and function correctly. I'm taking the userid and password and I want to check against a SQL table called User--All my information in three tables I want to store in Session variables. I'm drawing everything through stored procedures. I would prefer you resond to my actual email address until I'm back at work on Friday(if not dont' worry about it i'll eventually see what you posted back):


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Session("User") = ""
Session("empID") = ""
Session("SuperEmpID") = ""
Session("deptID") = ""
Session("currPeriod") = ""
Session("companyID") = ""
Session("facilityID") = ""
Session("Shift") = 0
Session("userName") = ""
Session("Role") = ""

End Sub

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim dataReader As SqlDataReader
Dim strPass, strUser As String

'Session("strUser") = txtUserID.Text
strUser = txtUserID.Text
strPass = txtPassword.Text

If strUser = "" Or strPass = "" Then
Response.Redirect("LogIn.aspx")
lblError.Text = "Your UserID or Password were incorrect. Please Try Again!"
End If

SqlCommand1.Parameters.Add(New SqlParameter("@dotnet.itags.org.strUser", strUser))
SqlCommand1.Parameters.Add(New SqlParameter("@dotnet.itags.org.strPass", strPass))

'Opens the connection to the DB
SqlConnection2.Open()

'Reads the data entered against SQL DB records
dataReader = SqlCommand1.ExecuteReader()

While dataReader.Read()
Session("User") = strUser
Session("SuperEmpID") = dataReader.GetString(1).ToString
Session("userName") = dataReader.GetString(2).ToString
Session("Role") = dataReader.GetString(3).ToString
Session("deptID") = dataReader.GetString(4).ToString
End While

dataReader.Close()

SqlCommand2.Parameters.Add(New SqlParameter("@dotnet.itags.org.deptID", Session("deptID")))
dataReader = SqlCommand2.ExecuteReader

While dataReader.Read
Session("companyID") = dataReader.GetString(1).ToString
Session("facilityID") = dataReader.GetString(2).ToString
Session("empID") = dataReader.GetString(4).ToString
Session("deptID") = dataReader.GetString(6).ToString
Session("Shift") = dataReader.GetString(8).ToString
End While

Response.Redirect("ReviewInterPersonal.aspx")
dataReader.Close()

'Closes Connection to DB
SqlConnection2.Close()
End Sub

much thanks,
jasonThe common method is to use Debug.Write to write out any messages you want. They'll show up in the output below when you run the application in the IDE.

The other thing I noticed is that you are using While loops. If you are only retrieving one row of data, you Simply use


DataReader.Read
Session("companyID) = dataReader.GetString(1).ToString

etc...

and then close it out like you are.

If you are retrieving multiple rows in your dataset, you need to be aware that each time you loop you are overwriting the prior values.

If you really need to store large amounts of data, you should consider using a DataSet with three datatable objects and then storing the DataSet in a Session Variable.

Friday, March 16, 2012

Newbie on Session State

Hello All!
Happy Friday, thank GOD!!!
So last night I realized I need to use Session State in my web application.
All I want to do is take the user name, and bring it back into any page I
want. I also have another web application built within my app, and I want to
be able to pull up that user name in the second web app as well.
Right now, after my user login in, they can go anywhere in my web app, but
when they jump over to the other web site, that app won't let them in. But I
thought if can carry the user info into that site, I should be good. I just
need a quick example or a good straight forward tutorial. Everything I been
finding has been just bit by bit info. I never done this, or seen it done,
so I would like to see a full simple example.

TIA!!!!

RudyHello Again.

OK, I'm a idiot. I didn't see my value that was coming up on the page, need
more coffee. So now I'm getting a pretty good handle on this, now that I
finally see how it works. It just scares me on home much stuff I don't know
that I could use to make my programming task so much easier.
Anyway, I''m still working on how to pass the info in my second app, would I
use this info in my global file?

Any thought would be great!

Thanks to all, have a great weekend!

Rudy

"Rudy" wrote:

> Hello All!
> Happy Friday, thank GOD!!!
> So last night I realized I need to use Session State in my web application.
> All I want to do is take the user name, and bring it back into any page I
> want. I also have another web application built within my app, and I want to
> be able to pull up that user name in the second web app as well.
> Right now, after my user login in, they can go anywhere in my web app, but
> when they jump over to the other web site, that app won't let them in. But I
> thought if can carry the user info into that site, I should be good. I just
> need a quick example or a good straight forward tutorial. Everything I been
> finding has been just bit by bit info. I never done this, or seen it done,
> so I would like to see a full simple example.
> TIA!!!!
> Rudy
>
A great way to do that is to...
1) Have a centralized Security model (e.g. Active Directory, a Single User
Database, Web Service, etc.)
2) have a single User Profile base. That could be a database, a web
service, or in the case of my company, we store the attributes inside of
Active Directory as well.

Then make all of your applications use those services.
if you have to worry about how AppX passes data to AppY, that's easy...but
when Appx, Appy, Appz and AppW all need to pass user information between
them, you have 12 possible paths for the information flow. Seperating it out
into a seperate service cleans all of that up.

"Rudy" wrote:

> Hello Again.
> OK, I'm a idiot. I didn't see my value that was coming up on the page, need
> more coffee. So now I'm getting a pretty good handle on this, now that I
> finally see how it works. It just scares me on home much stuff I don't know
> that I could use to make my programming task so much easier.
> Anyway, I''m still working on how to pass the info in my second app, would I
> use this info in my global file?
> Any thought would be great!
> Thanks to all, have a great weekend!
> Rudy
> "Rudy" wrote:
> > Hello All!
> > Happy Friday, thank GOD!!!
> > So last night I realized I need to use Session State in my web application.
> > All I want to do is take the user name, and bring it back into any page I
> > want. I also have another web application built within my app, and I want to
> > be able to pull up that user name in the second web app as well.
> > Right now, after my user login in, they can go anywhere in my web app, but
> > when they jump over to the other web site, that app won't let them in. But I
> > thought if can carry the user info into that site, I should be good. I just
> > need a quick example or a good straight forward tutorial. Everything I been
> > finding has been just bit by bit info. I never done this, or seen it done,
> > so I would like to see a full simple example.
> > TIA!!!!
> > Rudy
Thanks David!

"David Jessee" wrote:

> A great way to do that is to...
> 1) Have a centralized Security model (e.g. Active Directory, a Single User
> Database, Web Service, etc.)
> 2) have a single User Profile base. That could be a database, a web
> service, or in the case of my company, we store the attributes inside of
> Active Directory as well.
> Then make all of your applications use those services.
> if you have to worry about how AppX passes data to AppY, that's easy...but
> when Appx, Appy, Appz and AppW all need to pass user information between
> them, you have 12 possible paths for the information flow. Seperating it out
> into a seperate service cleans all of that up.
> "Rudy" wrote:
> > Hello Again.
> > OK, I'm a idiot. I didn't see my value that was coming up on the page, need
> > more coffee. So now I'm getting a pretty good handle on this, now that I
> > finally see how it works. It just scares me on home much stuff I don't know
> > that I could use to make my programming task so much easier.
> > Anyway, I''m still working on how to pass the info in my second app, would I
> > use this info in my global file?
> > Any thought would be great!
> > Thanks to all, have a great weekend!
> > Rudy
> > "Rudy" wrote:
> > > Hello All!
> > > Happy Friday, thank GOD!!!
> > > So last night I realized I need to use Session State in my web application.
> > > All I want to do is take the user name, and bring it back into any page I
> > > want. I also have another web application built within my app, and I want to
> > > be able to pull up that user name in the second web app as well.
> > > Right now, after my user login in, they can go anywhere in my web app, but
> > > when they jump over to the other web site, that app won't let them in. But I
> > > thought if can carry the user info into that site, I should be good. I just
> > > need a quick example or a good straight forward tutorial. Everything I been
> > > finding has been just bit by bit info. I never done this, or seen it done,
> > > so I would like to see a full simple example.
> > > > TIA!!!!
> > > > Rudy
> >