Session doesn't work in Application_Error in Global.aspx

Discussion in 'ASP .Net' started by Mike Malter, Feb 28, 2004.

  1. Mike Malter

    Mike Malter Guest

    I have a general error page that I configured in web.config as
    <customErrors mode="On" defaultRedirect="CRDefaultError.aspx" />
    This error page comes up whenever an error occurs outside of any try/catch blocks.

    This page has a text box in it that I would like to fill with relevant information about the error. I am trying to put the
    Server.GetLastError().ToString() in there. It did not work on the page, and I read somewhere that I should create a session
    variable in the Application_Error event in Global.aspx. My problem is that if I try to create a session variable in
    Application_Error, it throws another error!

    So, is there anyway that I can simply grab the Server.GetLastError().ToString() and get to it in my custom error page?

    Thanks.

    Mike
    Mike Malter, Feb 28, 2004
    #1
    1. Advertising

  2. Mike Malter

    Mike Malter Guest

    Marshal,

    Thanks. I'll try this.

    Mike

    "Marshal Antony" <> wrote in message news:%23pgLX6n$...
    > Hi Mike,
    > Use your Server.GetLastError() in Application_Error event handler in
    > Global.asax.cs. and store it in a Session variable there.
    > protected void Application_Error(Object sender, EventArgs e)
    >
    > {
    >
    > Exception last_Error=Server.GetLastError();
    >
    > if(last_Error!=null)
    >
    > {
    >
    > Session["last_Error"]=last_Error.ToString();
    >
    > // You can redirect to your custom error page from here and can access the
    > Session variable Session["last_Error"] from there.
    >
    > Response.Redirect("CRDefaultError.aspx");
    >
    > }
    >
    > Hope this helps.
    >
    > Regards,
    >
    > Marshal Antony
    >
    > .NET Developer
    >
    > http://www.dotnetmarshal.com
    >
    >
    >
    >
    >
    >
    >
    > "Mike Malter" <> wrote in message
    > news:uG1w13c$...
    > > I have a general error page that I configured in web.config as
    > > <customErrors mode="On" defaultRedirect="CRDefaultError.aspx" />
    > > This error page comes up whenever an error occurs outside of any try/catch

    > blocks.
    > >
    > > This page has a text box in it that I would like to fill with relevant

    > information about the error. I am trying to put the
    > > Server.GetLastError().ToString() in there. It did not work on the page,

    > and I read somewhere that I should create a session
    > > variable in the Application_Error event in Global.aspx. My problem is

    > that if I try to create a session variable in
    > > Application_Error, it throws another error!
    > >
    > > So, is there anyway that I can simply grab the

    > Server.GetLastError().ToString() and get to it in my custom error page?
    > >
    > > Thanks.
    > >
    > > Mike
    > >
    > >
    > >
    > >

    >
    >
    Mike Malter, Feb 29, 2004
    #2
    1. Advertising

  3. Mike Malter

    Mike Malter Guest

    Marshal,

    The problem here is still the same, whenever I try to assign a value to a session variable in the Application_OnError event I get
    another error.

    Any thoughts?

    Thanks.

    Mike

    "Marshal Antony" <> wrote in message news:%23pgLX6n$...
    > Hi Mike,
    > Use your Server.GetLastError() in Application_Error event handler in
    > Global.asax.cs. and store it in a Session variable there.
    > protected void Application_Error(Object sender, EventArgs e)
    >
    > {
    >
    > Exception last_Error=Server.GetLastError();
    >
    > if(last_Error!=null)
    >
    > {
    >
    > Session["last_Error"]=last_Error.ToString();
    >
    > // You can redirect to your custom error page from here and can access the
    > Session variable Session["last_Error"] from there.
    >
    > Response.Redirect("CRDefaultError.aspx");
    >
    > }
    >
    > Hope this helps.
    >
    > Regards,
    >
    > Marshal Antony
    >
    > .NET Developer
    >
    > http://www.dotnetmarshal.com
    >
    >
    >
    >
    >
    >
    >
    > "Mike Malter" <> wrote in message
    > news:uG1w13c$...
    > > I have a general error page that I configured in web.config as
    > > <customErrors mode="On" defaultRedirect="CRDefaultError.aspx" />
    > > This error page comes up whenever an error occurs outside of any try/catch

    > blocks.
    > >
    > > This page has a text box in it that I would like to fill with relevant

    > information about the error. I am trying to put the
    > > Server.GetLastError().ToString() in there. It did not work on the page,

    > and I read somewhere that I should create a session
    > > variable in the Application_Error event in Global.aspx. My problem is

    > that if I try to create a session variable in
    > > Application_Error, it throws another error!
    > >
    > > So, is there anyway that I can simply grab the

    > Server.GetLastError().ToString() and get to it in my custom error page?
    > >
    > > Thanks.
    > >
    > > Mike
    > >
    > >
    > >
    > >

    >
    >
    Mike Malter, Mar 1, 2004
    #3
  4. Hi Mike,
    Use your Server.GetLastError() in Application_Error event handler in
    Global.asax.cs. and store it in a Session variable there.
    protected void Application_Error(Object sender, EventArgs e)

    {

    Exception last_Error=Server.GetLastError();

    if(last_Error!=null)

    {

    Session["last_Error"]=last_Error.ToString();

    // You can redirect to your custom error page from here and can access the
    Session variable Session["last_Error"] from there.

    Response.Redirect("CRDefaultError.aspx");

    }

    Hope this helps.

    Regards,

    Marshal Antony

    ..NET Developer

    http://www.dotnetmarshal.com







    "Mike Malter" <> wrote in message
    news:uG1w13c$...
    > I have a general error page that I configured in web.config as
    > <customErrors mode="On" defaultRedirect="CRDefaultError.aspx" />
    > This error page comes up whenever an error occurs outside of any try/catch

    blocks.
    >
    > This page has a text box in it that I would like to fill with relevant

    information about the error. I am trying to put the
    > Server.GetLastError().ToString() in there. It did not work on the page,

    and I read somewhere that I should create a session
    > variable in the Application_Error event in Global.aspx. My problem is

    that if I try to create a session variable in
    > Application_Error, it throws another error!
    >
    > So, is there anyway that I can simply grab the

    Server.GetLastError().ToString() and get to it in my custom error page?
    >
    > Thanks.
    >
    > Mike
    >
    >
    >
    >
    Marshal Antony, Mar 29, 2004
    #4
    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,007
    Alvin Bruney
    Dec 22, 2003
  2. Mark
    Replies:
    0
    Views:
    2,390
  3. vikram
    Replies:
    1
    Views:
    852
    Karl Seguin [MVP]
    Oct 4, 2006
  4. BenCoo
    Replies:
    4
    Views:
    4,950
    Juan T. Llibre
    Jun 3, 2007
  5. jvcoach23
    Replies:
    25
    Views:
    3,357
    Juan T. Llibre
    Jan 16, 2008
Loading...

Share This Page