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

Use "Session" from page requested by code

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.HttpConte xt.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"]];
}


"Peter Theill" <as**@asdf.com> wrote in message
news:eH**************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #2

P: n/a
> 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
Nov 18 '05 #3

P: n/a
> 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
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.