session state is not available in this context

Discussion in '.NET' started by AliD, Dec 1, 2009.

  1. AliD

    AliD

    Joined:
    Dec 1, 2009
    Messages:
    2
    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");
    
     
    AliD, Dec 1, 2009
    #1
    1. Advertising

  2. AliD

    navyjax2

    Joined:
    Sep 20, 2008
    Messages:
    11
    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
     
    navyjax2, Feb 5, 2010
    #2
    1. Advertising

  3. AliD

    AliD

    Joined:
    Dec 1, 2009
    Messages:
    2
    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
     
    AliD, Feb 7, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UmFodWxfQm9yYWRl?=

    Session state is not available in this context.

    =?Utf-8?B?UmFodWxfQm9yYWRl?=, Nov 6, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    488
    =?Utf-8?B?UmFodWxfQm9yYWRl?=
    Nov 6, 2004
  2. kingski
    Replies:
    1
    Views:
    4,143
    bruce barker \(sqlwork.com\)
    May 11, 2006
  3. =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    RE: Session state is not available in this context. - (For certain fi

    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Mar 28, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    517
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Mar 28, 2007
  4. =?Utf-8?B?Yg==?=
    Replies:
    0
    Views:
    449
    =?Utf-8?B?Yg==?=
    Mar 28, 2007
  5. =?Utf-8?B?RnJhbmsxMjEz?=

    Session state is not available in this context

    =?Utf-8?B?RnJhbmsxMjEz?=, Nov 16, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    427
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Nov 16, 2007
Loading...

Share This Page