473,511 Members | 15,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2411
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2363
by: Arnaldo Martinez | last post by:
Hi, friends: I have an ASP page where an user enter a value and click the submit button. I want this value to be transfer to a session("temp") within the same page where I want to call it back...
14
5894
by: dale zhang | last post by:
Hi groups, Can anyone give me the equivalent C# sharp code for this VB.ET code, :: VB.NET :: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles...
4
1637
by: VB Programmer | last post by:
If I have a variable I want to share in my application what is the difference between just declaring a variable (Dim strMyVar as String) and using a session variable (Session("strMyVar"))? When...
3
2098
by: Jeff Smythe | last post by:
I simply want to execute some code once when a new session of my ASP.NET application is started (I'm not using session state for anything else - just writing some data to a database). I thought...
5
1858
by: jensen bredal | last post by:
I need to keep track on user "session data" while still turning session off as i do not want users login to expire? Thanks JB
10
2368
by: thomson | last post by:
Hi, i create a session variable in C# as follows Session , but iam not able to access the variable in VB.net like intmode=Session("var"); Why is that ? Regards
2
2055
by: Athenian | last post by:
Hi guys. Currently I need a javascript (client side) or vbscript(server side) code to check automatically for session expiration and force the redirection to a message page or the log-in page....
3
34441
by: Paul | last post by:
Hi All, In my application, I wished to check certain things on each page load, so rather than paste the same code in each pages constructor, I thought it would be more logical to inherit from...
4
2090
by: R.A.M. | last post by:
Hello, I am writing ASP.NET application in which I need to use User Profiles and Session mechanisms. Here I include part of my source code (Admin.cs): using System; using System.Data; using...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.