By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,769 Members | 1,819 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,769 IT Pros & Developers. It's quick & easy.

Accessing Session State across pages

P: n/a
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()
Dec 5 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.

"gom" <go*@g.gwrote in message
news:eL**************@TK2MSFTNGP04.phx.gbl...
>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()

Dec 5 '07 #2

P: n/a
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

"gom" wrote:
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()
Dec 5 '07 #3

P: n/a
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.

"Aidy" <ai**@xxnoemailxx.comwrote in message
news:nY******************************@bt.com...
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.

"gom" <go*@g.gwrote in message
news:eL**************@TK2MSFTNGP04.phx.gbl...
>>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()


Dec 5 '07 #4

P: n/a
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?

"Peter Bromberg [C# MVP]" <pb*******@yahoo.NoSpamMaam.comwrote in message
news:F3**********************************@microsof t.com...
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

"gom" wrote:
>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()

Dec 5 '07 #5

P: n/a
"gom" <go*@g.gwrote in message
news:eL**************@TK2MSFTNGP04.phx.gbl...
>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
Dec 5 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.