session state is not available in this context

Joined
Dec 1, 2009
Messages
2
Reaction score
0
hi,
i'm having some trouble with my global.asax file,
i'm trying to write my own method in there to raise an error, and then
use Response.Redirect to redirect it to an error page, to display the error message ....
the logic is quite simple, but when i use the session i always get
"Session state is not available in this context"... and i really don't know why?
and i don't know what to do..
below is my code...
any help would be appreciated..
Code:
                object user = (object)Session["Info"];
                Session.Clear();
                Session["Info"] = user;
                Session["ErrorMessage"] = ErrorMessage;

                // this part to show a home button in the error page
                if (ShowHomeButton)
                    Session["ShowHomeButton"] = 1;
                else
                    Session["ShowHomeButton"] = 0;
           
                // this part to redirect to the error page
                Response.Redirect("~/ErrorPage.aspx");
 
Joined
Sep 20, 2008
Messages
11
Reaction score
0
Session state doesn't seem to avail itself to anything but the _Default partial class that inherits System.Web.UI.Page in a Default.aspx.cs, from what I've been able to figure out so far. I think this means that unless you are inheriting or instantiating Page page = this.Page(); or System.Web.UI.Page somehow, you lose the ability to capture values into session state because you are not part of "the page". There has to be a way to do it, but I think that I at least understand why the context is not permitted without some extra coding.

HTH,
-Tom
 
Joined
Dec 1, 2009
Messages
2
Reaction score
0
well, yeah thanks, i could figure that out, and i had to remove my session logic to a class that ,as u mentioned earlier , inherits System.Web.UI.Page
i guess this is the only way to do it, and i think it has something to do with the sequence of events in requesting and loading a web page
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top