473,230 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

ASP.NET 1.1 HttpContext.Session question

Hi,
I have a web application, code of ASPX page needs to call one static
method in another class which does not inherit System.UI.Page class

using System.Web;

public class Utils {
public static void GetSessions() {
HttpContext ctx = HttpContext.Current;
ctx.Session; // not available. <undefined value>
ctx.Cache; // Yes!! I can access.
}
}

If I place a quick watch on ctx variable, I noticed Session is not
availble to use, but Cache is ready.

Anybody has idea how can I access Session objects from other class? And
why I cannot access it via HttpContext?

Thanks for any suggestion.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Jan 25 '06 #1
7 4224
put in a page1.aspx

Do NOTHING on this page, except put a button on it, redirecting to another
page.
like this:
Response.Redirect("page2.aspx");
ok.. now debug your stuff. (aka, don't call Utils.GetSessions() until you're
on page2.aspx) (but you *must* redirect from page1.aspx)

I think the Session will be available on the second page.

...


"Hardy Wang" <ha*******@newsgroups.nospam> wrote in message
news:uS**************@TK2MSFTNGP09.phx.gbl...
Hi,
I have a web application, code of ASPX page needs to call one static
method in another class which does not inherit System.UI.Page class

using System.Web;

public class Utils {
public static void GetSessions() {
HttpContext ctx = HttpContext.Current;
ctx.Session; // not available. <undefined value>
ctx.Cache; // Yes!! I can access.
}
}

If I place a quick watch on ctx variable, I noticed Session is not
availble to use, but Cache is ready.

Anybody has idea how can I access Session objects from other class? And why I cannot access it via HttpContext?

Thanks for any suggestion.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy

Jan 25 '06 #2
Thanks,
But I have to put this piece of code in a separate class out of web
page.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"sloan" <sl***@ipass.net> wrote in message
news:ei*************@TK2MSFTNGP10.phx.gbl...
put in a page1.aspx

Do NOTHING on this page, except put a button on it, redirecting to another
page.
like this:
Response.Redirect("page2.aspx");
ok.. now debug your stuff. (aka, don't call Utils.GetSessions() until
you're
on page2.aspx) (but you *must* redirect from page1.aspx)

I think the Session will be available on the second page.

..


"Hardy Wang" <ha*******@newsgroups.nospam> wrote in message
news:uS**************@TK2MSFTNGP09.phx.gbl...
Hi,
I have a web application, code of ASPX page needs to call one static
method in another class which does not inherit System.UI.Page class

using System.Web;

public class Utils {
public static void GetSessions() {
HttpContext ctx = HttpContext.Current;
ctx.Session; // not available. <undefined value>
ctx.Cache; // Yes!! I can access.
}
}

If I place a quick watch on ctx variable, I noticed Session is not
availble to use, but Cache is ready.

Anybody has idea how can I access Session objects from other class?

And
why I cannot access it via HttpContext?

Thanks for any suggestion.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy


Jan 25 '06 #3

That's fine, you can do what you want.
What I am saying is that the Session may not be available UNTIL AFTER (at
least) one aspx page loads.
That has nothing to do with where you write/store the code.
I'm trying to show you when Session becomes "alive", not where to put your
code.
...

"Hardy Wang" <ha*******@newsgroups.nospam> wrote in message
news:#$*************@tk2msftngp13.phx.gbl...
Thanks,
But I have to put this piece of code in a separate class out of web
page.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"sloan" <sl***@ipass.net> wrote in message
news:ei*************@TK2MSFTNGP10.phx.gbl...
put in a page1.aspx

Do NOTHING on this page, except put a button on it, redirecting to another page.
like this:
Response.Redirect("page2.aspx");
ok.. now debug your stuff. (aka, don't call Utils.GetSessions() until
you're
on page2.aspx) (but you *must* redirect from page1.aspx)

I think the Session will be available on the second page.

..


"Hardy Wang" <ha*******@newsgroups.nospam> wrote in message
news:uS**************@TK2MSFTNGP09.phx.gbl...
Hi,
I have a web application, code of ASPX page needs to call one static method in another class which does not inherit System.UI.Page class

using System.Web;

public class Utils {
public static void GetSessions() {
HttpContext ctx = HttpContext.Current;
ctx.Session; // not available. <undefined value>
ctx.Cache; // Yes!! I can access.
}
}

If I place a quick watch on ctx variable, I noticed Session is not
availble to use, but Cache is ready.

Anybody has idea how can I access Session objects from other class?

And
why I cannot access it via HttpContext?

Thanks for any suggestion.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy



Jan 25 '06 #4
Hardy ,

That basically means that the HttpHandler that process the request is not
marked with one of the marker interfaces IRequiresSessionState or I
ReadOnlySessionState. In this case Session won't be created, but other think
like Cache for example will be avavilable.

This can happen if you have written your own HttpHandler or the page has
been set up not to have session state.
For the latter check if the @ Page directive in aspx file doesn't have
EnableSessionState=false. Also check if the session state is not disabled in
the web.config file - sessionState element's mode attribute doesn't have to
be *Off*.
--
HTH
Stoitcho Goutsev (100)
"Hardy Wang" <ha*******@newsgroups.nospam> wrote in message
news:uS**************@TK2MSFTNGP09.phx.gbl...
Hi,
I have a web application, code of ASPX page needs to call one static
method in another class which does not inherit System.UI.Page class

using System.Web;

public class Utils {
public static void GetSessions() {
HttpContext ctx = HttpContext.Current;
ctx.Session; // not available. <undefined value>
ctx.Cache; // Yes!! I can access.
}
}

If I place a quick watch on ctx variable, I noticed Session is not
availble to use, but Cache is ready.

Anybody has idea how can I access Session objects from other class? And
why I cannot access it via HttpContext?

Thanks for any suggestion.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy

Jan 25 '06 #5
sloan,

As I tried to explain in my other post creation of the session doesn't
depend on whether aspx page has been loaded or not. The SessionStateModule
initializes the context with session if the HttpHandle that is about to
process the request is marked with proper marker interface. The HttpHandler
could asp.net page, but might be custom written HttpModule.

Further more two pages in one application could be marked one to support
session state and the other not to.
--

Stoitcho Goutsev (100)
"sloan" <sl***@ipass.net> wrote in message
news:OT*************@TK2MSFTNGP12.phx.gbl...

That's fine, you can do what you want.
What I am saying is that the Session may not be available UNTIL AFTER (at
least) one aspx page loads.
That has nothing to do with where you write/store the code.
I'm trying to show you when Session becomes "alive", not where to put your
code.
..

"Hardy Wang" <ha*******@newsgroups.nospam> wrote in message
news:#$*************@tk2msftngp13.phx.gbl...
Thanks,
But I have to put this piece of code in a separate class out of web
page.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"sloan" <sl***@ipass.net> wrote in message
news:ei*************@TK2MSFTNGP10.phx.gbl...
> put in a page1.aspx
>
> Do NOTHING on this page, except put a button on it, redirecting to another > page.
> like this:
> Response.Redirect("page2.aspx");
>
>
> ok.. now debug your stuff. (aka, don't call Utils.GetSessions() until
> you're
> on page2.aspx) (but you *must* redirect from page1.aspx)
>
> I think the Session will be available on the second page.
>
> ..
>
>
>
>
> "Hardy Wang" <ha*******@newsgroups.nospam> wrote in message
> news:uS**************@TK2MSFTNGP09.phx.gbl...
>> Hi,
>> I have a web application, code of ASPX page needs to call one static >> method in another class which does not inherit System.UI.Page class
>>
>> using System.Web;
>>
>> public class Utils {
>> public static void GetSessions() {
>> HttpContext ctx = HttpContext.Current;
>> ctx.Session; // not available. <undefined value>
>> ctx.Cache; // Yes!! I can access.
>> }
>> }
>>
>> If I place a quick watch on ctx variable, I noticed Session is not
>> availble to use, but Cache is ready.
>>
>> Anybody has idea how can I access Session objects from other
>> class?
> And
>> why I cannot access it via HttpContext?
>>
>> Thanks for any suggestion.
>>
>> --
>> WWW: http://hardywang.1accesshost.com
>> ICQ: 3359839
>> yours Hardy
>>
>>
>
>



Jan 25 '06 #6
Use HttpContext.Current in your class.
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Hardy Wang" wrote:
Hi,
I have a web application, code of ASPX page needs to call one static
method in another class which does not inherit System.UI.Page class

using System.Web;

public class Utils {
public static void GetSessions() {
HttpContext ctx = HttpContext.Current;
ctx.Session; // not available. <undefined value>
ctx.Cache; // Yes!! I can access.
}
}

If I place a quick watch on ctx variable, I noticed Session is not
availble to use, but Cache is ready.

Anybody has idea how can I access Session objects from other class? And
why I cannot access it via HttpContext?

Thanks for any suggestion.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy

Jan 26 '06 #7
Pardon me. I should have read more carefully. I see that you aready tried
that.
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Dale" wrote:
Use HttpContext.Current in your class.
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Hardy Wang" wrote:
Hi,
I have a web application, code of ASPX page needs to call one static
method in another class which does not inherit System.UI.Page class

using System.Web;

public class Utils {
public static void GetSessions() {
HttpContext ctx = HttpContext.Current;
ctx.Session; // not available. <undefined value>
ctx.Cache; // Yes!! I can access.
}
}

If I place a quick watch on ctx variable, I noticed Session is not
availble to use, but Cache is ready.

Anybody has idea how can I access Session objects from other class? And
why I cannot access it via HttpContext?

Thanks for any suggestion.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy

Jan 26 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Francois Malgreve | last post by:
hello guys, I have some helper class in my ASP.NET pplication who basically contains static methods. I used them as helper methods to do small jobs that I can use at many places in my code. ...
2
by: moondaddy | last post by:
I need to set a variable to a session variable (if that's what you call it) like this: dim ds as dataset = HttpContext.Current.Session("CustDataSet") But I get an exception if this variable...
4
by: Makarand Keer | last post by:
Hi All I have problem in using Threading. I have ASP.NET application in which I am using multithreading to start a process. Now the object instances which are used in this thread access...
15
by: Jason | last post by:
Currently, I am storing information about the currently logged on user in Session variables that are stored in SQL. However, I am using role-based security, so I am storing custom roles in a...
7
by: Hardy Wang | last post by:
Hi, I have a web application, code of ASPX page needs to call one static method in another class which does not inherit System.UI.Page class using System.Web; public class Utils { public...
6
by: Sjaakie | last post by:
Hi, Is HttpContext.Current.User unique for each visitor or is it shared across an application? Have some problems that might have to do with this and found contradictory answers on this...
2
by: Dave | last post by:
After some digging, I discovered HttpContext.Current.Session is null when trying to access a session variable, username, in my upload.cs code which is in the App_Code folder. I just determined...
14
by: R.A.M. | last post by:
Hello, I have created ASP.NET project in which I have a file Admin.cs. It contains static class Admin with some methods and properties. The problem is that in property get a reference...
3
by: Madhur | last post by:
Hello I am delivering an asp.net 2.0 application to my customer. I need to know, If I need to check for the condition of HttpContext.Current to be null in my business logic. I have extensively...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.