Writing an exception to both the event log and to an error page

Discussion in 'ASP .Net Security' started by Nam, Jul 22, 2008.

  1. Nam

    Nam Guest

    In a C# class of an ASP.NET application, I am logging the exceptions to the
    windows even log. How can I simultaneously propagate the exception on top and
    let the Page that calls that C# class to catch the exception?

    After catching the exception, I would redirect a customized message to an
    error page.

    Thank you in advance.
    Nam, Jul 22, 2008
    #1
    1. Advertising

  2. Nam

    JJ Guest

    Should just have to rethrow it.

    Try
    <code>
    Catch Ex as Exception
    <code here to log to event log>
    Throw Ex
    End Try

    "Nam" wrote:

    > In a C# class of an ASP.NET application, I am logging the exceptions to the
    > windows even log. How can I simultaneously propagate the exception on top and
    > let the Page that calls that C# class to catch the exception?
    >
    > After catching the exception, I would redirect a customized message to an
    > error page.
    >
    > Thank you in advance.
    JJ, Jul 22, 2008
    #2
    1. Advertising

  3. Nam

    sloan Guest

    I would try this, which I think keeps the original stack trace.


    try
    {

    }
    catch (Exception ex)
    {

    //publish it to the event log
    throw;

    }


    Or change it to
    throw ex;

    But there is a subtle difference.



    "JJ" <> wrote in message
    news:...
    > Should just have to rethrow it.
    >
    > Try
    > <code>
    > Catch Ex as Exception
    > <code here to log to event log>
    > Throw Ex
    > End Try
    >
    > "Nam" wrote:
    >
    >> In a C# class of an ASP.NET application, I am logging the exceptions to
    >> the
    >> windows even log. How can I simultaneously propagate the exception on top
    >> and
    >> let the Page that calls that C# class to catch the exception?
    >>
    >> After catching the exception, I would redirect a customized message to an
    >> error page.
    >>
    >> Thank you in advance.
    sloan, Jul 22, 2008
    #3
  4. Nam

    Nam Guest

    RE: Writing an exception to both the event log and to an error pag

    JJ,

    Thank you very much. I used your suggestion and it worked perfectly.

    Nam

    "JJ" wrote:

    > Should just have to rethrow it.
    >
    > Try
    > <code>
    > Catch Ex as Exception
    > <code here to log to event log>
    > Throw Ex
    > End Try
    >
    > "Nam" wrote:
    >
    > > In a C# class of an ASP.NET application, I am logging the exceptions to the
    > > windows even log. How can I simultaneously propagate the exception on top and
    > > let the Page that calls that C# class to catch the exception?
    > >
    > > After catching the exception, I would redirect a customized message to an
    > > error page.
    > >
    > > Thank you in advance.
    Nam, Jul 24, 2008
    #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. =?Utf-8?B?VG9tIFdpbmdlcnQ=?=

    My.Log.Writeexception not writing to Application Event Log.

    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=, Jan 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,371
    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=
    Jan 20, 2006
  2. =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=

    security exception writing to event log

    =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=, Nov 15, 2006, in forum: ASP .Net
    Replies:
    10
    Views:
    838
    Walter Wang [MSFT]
    Nov 16, 2006
  3. ABCL
    Replies:
    0
    Views:
    546
  4. Nam
    Replies:
    3
    Views:
    478
  5. Tom Wingert
    Replies:
    0
    Views:
    330
    Tom Wingert
    Jan 12, 2006
Loading...

Share This Page