Accessing Session State across pages

G

gom

I am an amatuer asp.net programmer so I hope this question isn't to dumb.

I am having difficulty with my understanding of session state. I have an
application that stores some values in the session and then I use the
following code to try and get a stream of image data. mypage.aspx has a
different session ID then the calling page. I tried to use a relative URI
but the getresponse said it couldn't use a relative uri. I've looked at
cookie containers but can't quite seem to make them work. I thought that
session variables would be available to all pages in my app but I'm thinking
that the code below must somehow create, almost like a new instance of
something that gets it's own session ID. Can anyone suggest what I am
missing or where I am going wrong?

Thanks in advance for any help.

Dim myURI As New Uri(http://mysite.com/myapp/mypage.aspx)
Dim myRequest As System.Net.HttpWebRequest =
System.Net.WebRequest.Create(myURI)
Dim myResponse As System.Net.HttpWebResponse = myRequest.GetResponse
Dim responseStream As System.IO.Stream = myResponse.GetResponseStream()
 
A

Aidy

Your asp.net code calling mypage.aspx will have its own session, separate
from the one the client on a remote machine has from the asp.net site. This
is by design. What is mypage.aspx doing? Maybe you can re-architect it.
 
P

Peter Bromberg [C# MVP]

The problem you have here is that you aren't requesting a page in the normal
way one would navigate a web site, in which case the SessionID cookie would
automatically be transmitted by the browser. What you are doing is
programmatically requesting a page via the HttpWebRequest / Response classes.

if all this does is get an image, what do you need Session for? You cannot
attach Session to something requested over http in this manner.
-- Peter
Site: www.eggheadcafe.com
UnBlog: petesbloggerama.blogspot.com
Metafinder: www.blogmetafinder.com
 
G

gom

It is using some session variables, created by the calling page, to modify
an image and then return it. If I embed an imagecontrol in the calling page
I can pass mypage.aspx and it gets the image modified by my session state
data. I want to get that same image back but in a responsestream. I can
see what you are saying about client vs server. I was sort of seeing that
as what was wrong but my understanding is still limited. Is there a better
way to create and store this data for use in a session? Cookies? Any
examples on the web you can point me to?

Thanks for your help.
 
G

gom

I believe I have caused a problem for myself by trying to extend some code
in the wrong fashion. mypage.aspx was first used to get an image and show
it in an imagecontrol. Now I just want the response stream. I probably
should just write a function or sub that does what mypage.aspx does and use
it to get my image data. That way it is all happening on the server.

Does that make sense?
 
B

Bjorn Sagbakken

gom said:
I am an amatuer asp.net programmer so I hope this question isn't to dumb.

I am having difficulty with my understanding of session state. I have an
application that stores some values in the session and then I use the
following code to try and get a stream of image data. mypage.aspx has a
different session ID then the calling page. I tried to use a relative URI
but the getresponse said it couldn't use a relative uri. I've looked at
cookie containers but can't quite seem to make them work. I thought that
session variables would be available to all pages in my app but I'm
thinking that the code below must somehow create, almost like a new
instance of something that gets it's own session ID. Can anyone suggest
what I am missing or where I am going wrong?

Thanks in advance for any help.

Dim myURI As New Uri(http://mysite.com/myapp/mypage.aspx)
Dim myRequest As System.Net.HttpWebRequest =
System.Net.WebRequest.Create(myURI)
Dim myResponse As System.Net.HttpWebResponse = myRequest.GetResponse
Dim responseStream As System.IO.Stream = myResponse.GetResponseStream()

I may be missing what you are trying to accieve, but if I wanted to transfer
a stream of image data from one form to another, I would do it like this:

Dim myStream as Stream
' add your data to myStream here
Session("myStream")=myStream '//here the stream is stored in as session
variable called myStream

In the other form you just retrieve this stream of data the opposite way:
Dim myStream as Stream=Session("myStream")

Very easy. I use it a lot.

Bjorn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top