Use "Session" from page requested by code

P

Peter Theill

Hi,

I'm trying to include the content of a request into an Xml document:

if (System.Web.HttpContext.Current.Session["user_id"] != null) {
XmlDocument d = new XmlDocument();
d.Load(new XmlTextReader("http://localhost/page.aspx"));
}

The requested page (page.aspx) is an XHTML page so I'm able to parse it as a
document. However if I want to use the current session in that request to
'page.aspx' how would I do that?

In "page.aspx" I reference a UserControl having this code line:

string userId = (string)System.Web.HttpContext.Current.Session["user_id"];

It's empty even though I check for it (first linie) just before requesting
the page. Could anyone help?

// pt
 
B

bruce barker

1) use webclient and pass along the session cookie and creditials to fetch
the page, then load into the xml document.
2) write the session to a global cache, then pass the cache key

public class SessionCache {
public static Hashtable Sessions[] = new Hashtable();
}


if (System.Web.HttpContext.Current.Session["user_id"] != null) {
string key = System.Guid.NewGuid().ToString();
lock(typeof(SessionCache)) {

SessionCache.Sessions.Add(key,System.Web.HttpContext.Current.Session["user_i
d"]) ;
}
XmlDocument d = new XmlDocument();
d.Load(new XmlTextReader("http://localhost/page.aspx?key=" + key));

lock(typeof(SessionCache)) {
SessionCache.Sessions.Remove(key);
}
}

in the calling page

lock(typeof(SessionCache)) {
HttpSessionState session = (HttpSessionState)
SessionCache.Sessions[Request.Form["key"]];
}
 
P

Peter Theill

1) use webclient and pass along the session cookie and creditials to fetch
the page, then load into the xml document.
2) write the session to a global cache, then pass the cache key

Beautiful. Just what I needed. Thanks for the code snippets.


// pt
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top