Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Variable not carrying over in Xml Http request

Status
Not open for further replies.

firsttube

Technical User
Apr 21, 2004
165
0
0
CA
I have an asp page that sends an xml http request to another asp page which sends back some data. In the page sending the request, there is a session variable. The page receiveing the request uses that session variable. However, the page receiving the request is somehow not "getting" the session variable.

I send the request like this:
Code:
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
	objXmlHttp.setTimeouts 0,0,0,20000
	objXmlHttp.open "GET", url,False
	objXmlHttp.send
	If objXmlHttp.status = 200 then
				strXml = objXmlHttp.responseText
	End if
data is coming back, but the receiving page is not seing the value of the Session Variable. I have checked and the session varible does contain a value.

Do session variables not carry over in xml http requests?

If I put the value of the session variable into the url string, everything is fine.

Information is not Knowledge, Knowledge is not Wisdom, Wisdom is not Truth, Truth is not Beauty, Beauty is not Love, Love is not Music, Music is the best.
 
I'm thinking that the server looks at each xml http request as a separate session. Is this correct?


Information is not Knowledge, Knowledge is not Wisdom, Wisdom is not Truth, Truth is not Beauty, Beauty is not Love, Love is not Music, Music is the best.
 
I looked around with Google, and it seems that with an xmlHttp request that Session variables are lost. I don't have any definitive proof. But you can Google and see other examples.

As for the url string, do you not want to pass the variable in the url string?

If not, you can use the "POST" method and pass the variable.
If you are interested in that, please ask.

[monkey][snake] <.
 
How come the page sending the request and the responding page (as specified in the url variable) share session variable? even in theory? If you want the responding page be aware of some session variable, appending that info to the url by something like &session=xyz.
 
monksnake, thanks for the info. I did change it so the url contains the variable I need in the receiving page. It works fine.

I have done some checking on the web and it seems that the server perceives the request to the receiving asp page as a new session. So it makes sense that the session vars set in the sending page do not carry over.

I think this sort of thing only holds true for xml http request objects. I have another page that sets some session variables, and then retrieves a map image from another asp page using a regular querystring method:
Code:
<%
image = "[URL unfurl="true"]http://mypage.asp?address=123[/URL] main st"
%>
<img src="<%=image%>">
In this case, the "mypage.asp" page does recognize the session variables that were set in the sending page.



Information is not Knowledge, Knowledge is not Wisdom, Wisdom is not Truth, Truth is not Beauty, Beauty is not Love, Love is not Music, Music is the best.
 
it seems that the server perceives the request to the receiving asp page as a new session.

Well yes this makes perfect sense when you consider the fact that your objXmlHttp is making an independant HTTP request. The object is basically acting as its own web browser but rather than displaying pixels on a screen, it makes text available via the responseText property.
 
The reason the session variable is getting lost is because the session variable is based upon a single critical piece of information: a cookie with the assigned SessionId in it.
Now I cannot guarantee that IIS would give XMLHTTP access to the session variable that a page would get, only that it definately will not if you don't pass back your SessionId with the request.

Basically to add this into your HTTP request you would have to add a cookie into the headers in your request. Unfortunately the session id is encoded/encrypted in the HTML header and is not the number you get from Session.SessionId. Additionally you do not get access to this encoded string from Request.Cookies. However, you can access it directly if you parse the cookies yourself from Request.ServerVariables("HTTP_COOKIE")

Now I'm not sure I understand what your trying to do. If your trying to build a client-side script that requests some additional information via XMLHTTP and needs to stay in a single session than that is one path, a server-side XMLHTTP request somewhere is an entirely different matter (and that is what your code above is doing). Could you provide more information on what your doing so I don't explain the wrong one?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top