468,285 Members | 1,586 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,285 developers. It's quick & easy.

Use "Session" from page requested by code

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
3 2213
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
> 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
> 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.

Similar topics

14 posts views Thread by dale zhang | last post: by
5 posts views Thread by jensen bredal | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.