I know that I can access session state on an asp.net page
using Page objects, but how do I access store data in sessionstate from the
middle tiers? 8 1463
Leon wrote: I know that I can access session state on an asp.net page using Page objects, but how do I access store data in sessionstate from the middle tiers?
System.Web.HttpContext.Current.*
Works only if you are really in an HttpContext, that is: the call to your
method is caused by a Request (not a timer-tick or session_end)
Hans Kesting
Use System.Web.HttpContext.Current.Session ala:
HttpContext context = System.Web.HttpContext.Current;
if (context == null){ //not in a web environment
throw new exception("Function BLAH must be called from within a web
context");
}
string value = context.Session["blah"];
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Leon" <vn*****@msn.com> wrote in message
news:O$**************@tk2msftngp13.phx.gbl... I know that I can access session state on an asp.net page using Page objects, but how do I access store data in sessionstate from
the middle tiers?
So would this work? and how would I access the stored session data from
within my page?
Imports System.web
' Constructors
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
Public Sub LoadSession(ByVal ChoosenEmailAddress As String)
myEmailAddress = ChoosenEmailAddress
LoadFromEmail()
End Sub
' Private Code
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
Private Sub LoadFromEmail()
Dim dataUser As New Data.Student
Dim userRow As DataRow =
dataUser.RetrieveAccount(myEmailAddress)
Dim context As HttpContext = System.Web.HttpContext.Current
myFirstName = context.Session(CStr(userRow("FirstName")))
myLastName = context.Session(CStr(userRow("LastName")))
myPassword = context.Session(CStr(userRow("Password")))
myEmailAddress = context.Session(CStr(userRow("EmailAddress")))
End Sub
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:et**************@TK2MSFTNGP12.phx.gbl... Use System.Web.HttpContext.Current.Session ala:
HttpContext context = System.Web.HttpContext.Current; if (context == null){ //not in a web environment throw new exception("Function BLAH must be called from within a web context"); } string value = context.Session["blah"];
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Leon" <vn*****@msn.com> wrote in message news:O$**************@tk2msftngp13.phx.gbl... I know that I can access session state on an asp.net page using Page objects, but how do I access store data in sessionstate from the middle tiers?
Leon:
Your code confuses me slightly. It seems to me you are getting the user
data from the dataUser.RetrieveAccount function which returns a
DataRow...not sure why you need sessions in this case.
context.Session(Cstr(userRow("FirstName")))
I'm not sure what you are trying to do with the above line, couldn't you
just do:
myFirstName = cstr(userRow("FirstName")) ??
why do you need sessions at all?
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Leon" <vn*****@msn.com> wrote in message
news:uC****************@TK2MSFTNGP10.phx.gbl... So would this work? and how would I access the stored session data from within my page?
Imports System.web
' Constructors
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Public Sub LoadSession(ByVal ChoosenEmailAddress As String) myEmailAddress = ChoosenEmailAddress LoadFromEmail() End Sub
' Private Code
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub LoadFromEmail()
Dim dataUser As New Data.Student Dim userRow As DataRow = dataUser.RetrieveAccount(myEmailAddress) Dim context As HttpContext = System.Web.HttpContext.Current
myFirstName = context.Session(CStr(userRow("FirstName"))) myLastName = context.Session(CStr(userRow("LastName"))) myPassword = context.Session(CStr(userRow("Password"))) myEmailAddress =
context.Session(CStr(userRow("EmailAddress"))) End Sub
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:et**************@TK2MSFTNGP12.phx.gbl... Use System.Web.HttpContext.Current.Session ala:
HttpContext context = System.Web.HttpContext.Current; if (context == null){ //not in a web environment throw new exception("Function BLAH must be called from within a web context"); } string value = context.Session["blah"];
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Leon" <vn*****@msn.com> wrote in message news:O$**************@tk2msftngp13.phx.gbl... I know that I can access session state on an asp.net page using Page objects, but how do I access store data in sessionstate from the middle tiers?
I dispose of the dataset, I only use the function to retrieve the data, but
by putting the data in session state I can use myFirstName, myLastName, etc.
throughout my web application. Right?
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:eG***************@TK2MSFTNGP10.phx.gbl... Leon: Your code confuses me slightly. It seems to me you are getting the user data from the dataUser.RetrieveAccount function which returns a DataRow...not sure why you need sessions in this case.
context.Session(Cstr(userRow("FirstName")))
I'm not sure what you are trying to do with the above line, couldn't you just do:
myFirstName = cstr(userRow("FirstName")) ??
why do you need sessions at all?
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Leon" <vn*****@msn.com> wrote in message news:uC****************@TK2MSFTNGP10.phx.gbl... So would this work? and how would I access the stored session data from within my page?
Imports System.web
' Constructors '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Public Sub LoadSession(ByVal ChoosenEmailAddress As String) myEmailAddress = ChoosenEmailAddress LoadFromEmail() End Sub
' Private Code '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub LoadFromEmail()
Dim dataUser As New Data.Student Dim userRow As DataRow = dataUser.RetrieveAccount(myEmailAddress) Dim context As HttpContext = System.Web.HttpContext.Current
myFirstName = context.Session(CStr(userRow("FirstName"))) myLastName = context.Session(CStr(userRow("LastName"))) myPassword = context.Session(CStr(userRow("Password"))) myEmailAddress = context.Session(CStr(userRow("EmailAddress"))) End Sub
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:et**************@TK2MSFTNGP12.phx.gbl... > Use System.Web.HttpContext.Current.Session ala: > > HttpContext context = System.Web.HttpContext.Current; > if (context == null){ //not in a web environment > throw new exception("Function BLAH must be called from within a web > context"); > } > string value = context.Session["blah"]; > > Karl > > -- > MY ASP.Net tutorials > http://www.openmymind.net/ > > > "Leon" <vn*****@msn.com> wrote in message > news:O$**************@tk2msftngp13.phx.gbl... >> I know that I can access session state on an asp.net page >> using Page objects, but how do I access store data in sessionstate >> from > the >> middle tiers? >> >> > >
I don't see where you are putting it in the session...you want to do
something like this:
First time the user is loaded
Get the data from the database
store it in the sesssion:
context.Session("firstName", cstr(userRow("FirstName")))
context.Session("LastName", cstr(userRow("LastName")))
on subsequent requests, instead of getting it from the database, you can
simply get it from:
context.Session("firstName")
Also, instead of storing a bunch of indivdual fields, you might want to
consider creating a "user" class, and simply storing that
Dim u as new User()
u.FirstName = cstr(userRow("FirstName"))
u.LastName= cstr(userRow("LastName"))
context.Session("User", u)
and retrieving it via:
Dim u as User = ctype(session("User", User))
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Leon" <vn*****@msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... I dispose of the dataset, I only use the function to retrieve the data,
but by putting the data in session state I can use myFirstName, myLastName,
etc. throughout my web application. Right?
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:eG***************@TK2MSFTNGP10.phx.gbl... Leon: Your code confuses me slightly. It seems to me you are getting the user data from the dataUser.RetrieveAccount function which returns a DataRow...not sure why you need sessions in this case.
context.Session(Cstr(userRow("FirstName")))
I'm not sure what you are trying to do with the above line, couldn't you just do:
myFirstName = cstr(userRow("FirstName")) ??
why do you need sessions at all?
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Leon" <vn*****@msn.com> wrote in message news:uC****************@TK2MSFTNGP10.phx.gbl... So would this work? and how would I access the stored session data from within my page?
Imports System.web
' Constructors
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Public Sub LoadSession(ByVal ChoosenEmailAddress As String) myEmailAddress = ChoosenEmailAddress LoadFromEmail() End Sub
' Private Code
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub LoadFromEmail()
Dim dataUser As New Data.Student Dim userRow As DataRow = dataUser.RetrieveAccount(myEmailAddress) Dim context As HttpContext = System.Web.HttpContext.Current
myFirstName = context.Session(CStr(userRow("FirstName"))) myLastName = context.Session(CStr(userRow("LastName"))) myPassword = context.Session(CStr(userRow("Password"))) myEmailAddress = context.Session(CStr(userRow("EmailAddress"))) End Sub
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:et**************@TK2MSFTNGP12.phx.gbl... > Use System.Web.HttpContext.Current.Session ala: > > HttpContext context = System.Web.HttpContext.Current; > if (context == null){ //not in a web environment > throw new exception("Function BLAH must be called from within a web > context"); > } > string value = context.Session["blah"]; > > Karl > > -- > MY ASP.Net tutorials > http://www.openmymind.net/ > > > "Leon" <vn*****@msn.com> wrote in message > news:O$**************@tk2msftngp13.phx.gbl... >> I know that I can access session state on an asp.net page >> using Page objects, but how do I access store data in sessionstate >> from > the >> middle tiers? >> >> > >
Thanks Karl for all the help!
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:uh**************@TK2MSFTNGP10.phx.gbl... I don't see where you are putting it in the session...you want to do something like this:
First time the user is loaded Get the data from the database store it in the sesssion: context.Session("firstName", cstr(userRow("FirstName"))) context.Session("LastName", cstr(userRow("LastName")))
on subsequent requests, instead of getting it from the database, you can simply get it from: context.Session("firstName")
Also, instead of storing a bunch of indivdual fields, you might want to consider creating a "user" class, and simply storing that
Dim u as new User() u.FirstName = cstr(userRow("FirstName")) u.LastName= cstr(userRow("LastName")) context.Session("User", u)
and retrieving it via:
Dim u as User = ctype(session("User", User))
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Leon" <vn*****@msn.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... I dispose of the dataset, I only use the function to retrieve the data, but by putting the data in session state I can use myFirstName, myLastName, etc. throughout my web application. Right?
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:eG***************@TK2MSFTNGP10.phx.gbl... > Leon: > Your code confuses me slightly. It seems to me you are getting the > user > data from the dataUser.RetrieveAccount function which returns a > DataRow...not sure why you need sessions in this case. > > context.Session(Cstr(userRow("FirstName"))) > > I'm not sure what you are trying to do with the above line, couldn't > you > just do: > > myFirstName = cstr(userRow("FirstName")) ?? > > why do you need sessions at all? > > > Karl > > -- > MY ASP.Net tutorials > http://www.openmymind.net/ > > > "Leon" <vn*****@msn.com> wrote in message > news:uC****************@TK2MSFTNGP10.phx.gbl... >> So would this work? and how would I access the stored session data >> from >> within my page? >> >> Imports System.web >> >> ' Constructors >> > '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - >> - - >> >> Public Sub LoadSession(ByVal ChoosenEmailAddress As String) >> myEmailAddress = ChoosenEmailAddress >> LoadFromEmail() >> End Sub >> >> ' Private Code >> > '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - >> - - >> >> Private Sub LoadFromEmail() >> >> Dim dataUser As New Data.Student >> Dim userRow As DataRow = >> dataUser.RetrieveAccount(myEmailAddress) >> Dim context As HttpContext = >> System.Web.HttpContext.Current >> >> myFirstName = context.Session(CStr(userRow("FirstName"))) >> myLastName = context.Session(CStr(userRow("LastName"))) >> myPassword = context.Session(CStr(userRow("Password"))) >> myEmailAddress = > context.Session(CStr(userRow("EmailAddress"))) >> >> End Sub >> >> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME >> net> >> wrote in message news:et**************@TK2MSFTNGP12.phx.gbl... >> > Use System.Web.HttpContext.Current.Session ala: >> > >> > HttpContext context = System.Web.HttpContext.Current; >> > if (context == null){ //not in a web environment >> > throw new exception("Function BLAH must be called from within a >> > web >> > context"); >> > } >> > string value = context.Session["blah"]; >> > >> > Karl >> > >> > -- >> > MY ASP.Net tutorials >> > http://www.openmymind.net/ >> > >> > >> > "Leon" <vn*****@msn.com> wrote in message >> > news:O$**************@tk2msftngp13.phx.gbl... >> >> I know that I can access session state on an asp.net page >> >> using Page objects, but how do I access store data in sessionstate >> >> from >> > the >> >> middle tiers? >> >> >> >> >> > >> > >> >> > >
Leon wrote: I know that I can access session state on an asp.net page using Page objects, but how do I access store data in sessionstate from the middle tiers?
You don't. That would couple your middle tier to your web tier, rendering it
impossible to reuse. It also obfuscates your middle tier's API, as passing
around HttpSessionState is no better than passing around object arrays or
collections with arbitrary content, and may subtly induce statefulness.
Cheers,
--
Joerg Jooss www.joergjooss.de ne**@joergjooss.de This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Paul Yanzick |
last post by:
Hello,
I am trying to develop a book tracking application for my capstone in
school, and am running into a problem.
The application is an ASP.Net application written in C#. The first page you...
|
by: Nhi Lam |
last post by:
Hi,
I understand that there are 3 modes in which I can
configure the SessionStateModule. What I need is an out of
process Session State store with fail over support.
The "SQL Server Mode" seems...
|
by: Oleg Ogurok |
last post by:
Hi all,
Is there a way to read other people's session variables?
I understand it makes sense that session state is on per-user basis, but
still...
Is there a way to get a collection of all...
|
by: McGeeky |
last post by:
Is there a way to get a user control to remember its state across pages? I
have a standard page layout I use with a header and footer as user controls.
Each page uses the same layout by means of...
|
by: jb |
last post by:
*Please* help --- I'm tearing my hair out.
I want to use sessionstate in a webservice, accessed from a client, written
in script (JScript, InfoPath).
I have written my webservice (C# .NET). I...
|
by: Steven Blair |
last post by:
I have the following code:
Session = new CurrentUser("TEST");
When I postback to the server, the Session is null.
My guess is a only the refence to my actual class is stored, rather than
the...
|
by: Azrael |
last post by:
Hi,
I have an SSLStream and i want to resume the SSL-Session for another
connection to this server. How can i do this? I haven´t found any clues
for it in SSLStream, perhaps Negotiatestream...
|
by: Bhagya |
last post by:
Hello,
On the LogOut Page i have done Session.Abandon();
And on every Page, In the Page_Load Event i check if the session exists
and only then display data.
Now the problem is after i logout from...
|
by: Glenn |
last post by:
Hi
I've been experimenting with managing state using the Session object. I've
created a simple WS with a couple of methods, one which sets a string
value, another that retrieves it.
Each...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
| |