global.asax : Application_Error and Session don't work

Discussion in 'ASP .Net' started by BenCoo, Jun 3, 2007.

  1. BenCoo

    BenCoo Guest

    In my ASP.NET 2.0 application I have in the global.asax.file the following
    code

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    ' Code that runs when an unhandled error occurs
    This dousn't work !!! Get error "Session state is not available in this
    context."
    Dim ex As Exception
    ex = Server.GetLastError.InnerException
    Session("Exception") = ex
    Session("FilePath") = Server.MapPath(Me.ToString)
    Response.Redirect("ErrorPage.aspx")
    End Sub

    I've get the error "Session state is not available in this context." when
    there's an error on a page ...

    Thanks for any help on this ...

    Benny
     
    BenCoo, Jun 3, 2007
    #1
    1. Advertising

  2. BenCoo

    Mark Rae Guest

    Mark Rae, Jun 3, 2007
    #2
    1. Advertising

  3. BenCoo

    BenCoo Guest

    BenCoo, Jun 3, 2007
    #3
  4. Are you using code-behind ?

    If so, you need to use HttpContext.Current
    ..



    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ======================================
    "BenCoo" <> wrote in message
    news:xmB8i.212239$-ops.be...
    > In my ASP.NET 2.0 application I have in the global.asax.file the following code
    >
    > Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    > ' Code that runs when an unhandled error occurs
    > This dousn't work !!! Get error "Session state is not available in this context."
    > Dim ex As Exception
    > ex = Server.GetLastError.InnerException
    > Session("Exception") = ex
    > Session("FilePath") = Server.MapPath(Me.ToString)
    > Response.Redirect("ErrorPage.aspx")
    > End Sub
    >
    > I've get the error "Session state is not available in this context." when there's an error on a
    > page ...
    >
    > Thanks for any help on this ...
    >
    > Benny
    >
    >
     
    Juan T. Llibre, Jun 3, 2007
    #4
  5. Also, check out this blog :

    http://blogs.gotdotnet.com/mattwag/archive/2005/02/07/368605.aspx

    There's a workaround there, by Baryon, which uses an Application variable,
    and another workaround, by Naimish R. Dave, which lets you use Session variables.




    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ======================================
    "Juan T. Llibre" <> wrote in message
    news:...
    > Are you using code-behind ?
    >
    > If so, you need to use HttpContext.Current
    > .
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ======================================
    > "BenCoo" <> wrote in message
    > news:xmB8i.212239$-ops.be...
    >> In my ASP.NET 2.0 application I have in the global.asax.file the following code
    >>
    >> Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    >> ' Code that runs when an unhandled error occurs
    >> This dousn't work !!! Get error "Session state is not available in this context."
    >> Dim ex As Exception
    >> ex = Server.GetLastError.InnerException
    >> Session("Exception") = ex
    >> Session("FilePath") = Server.MapPath(Me.ToString)
    >> Response.Redirect("ErrorPage.aspx")
    >> End Sub
    >>
    >> I've get the error "Session state is not available in this context." when there's an error on a
    >> page ...
    >>
    >> Thanks for any help on this ...
    >>
    >> Benny
    >>
    >>

    >
    >
     
    Juan T. Llibre, Jun 3, 2007
    #5
    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. tafs7
    Replies:
    3
    Views:
    4,037
    Alvin Bruney
    Dec 22, 2003
  2. Mark
    Replies:
    0
    Views:
    2,417
  3. =?Utf-8?B?YmNoYXJsZXM=?=

    global.asax and global.asax.cs

    =?Utf-8?B?YmNoYXJsZXM=?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    899
    =?Utf-8?B?YmNoYXJsZXM=?=
    Oct 5, 2004
  4. Mark Rae

    Global.asax / Global.asax.cs in v2

    Mark Rae, May 23, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    3,198
    Mark Rae
    May 23, 2006
  5. vikram
    Replies:
    1
    Views:
    873
    Karl Seguin [MVP]
    Oct 4, 2006
Loading...

Share This Page