Exception handling in web applications

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kshitij

    Exception handling in web applications

    Hi,

    How to handle exceptions and show messages in a web application? In windows application we can create a log file and show the message on message box.What is the way to do it in a web application?

    Thanks in advance.
  • William Ryan  eMVP

    #2
    Re: Exception handling in web applications

    Be very careful here! I was just at a TechNet discussion and the subject
    was Web Security and one of the biggest points they made was not exposing
    exceptions to users. Hackers will often try to break the app and gain info
    from the exception message. One fairly large company got one of their
    primary tables truncated and the attacker was able to do it by injection
    attacks coupled with info from the exception message which told him what to
    hit.

    You have a few choices as far as developer exceptions go. First off, I'd
    recommend against using MessageBoxes, use assertions and in the try catch
    block use Debug.Assert(fa lse, ex.ToString()); it'll give you a little more
    flexibility. Either way it's not going to happen with the web. You could
    serialize your exceptions and write them to an XML file for one thing. Many
    times we use debug constants and set a place on the web server to write
    exceptions when it's in debug mode. Then when we switch to release, it stops
    and all is good. YOu can also write to event logs although you'll need some
    increased permissions to do this and if your app throws a lot of exceptions,
    they can fill up quickly (although it takes a fair volume to do this to the
    point its a pain for most small to mid sized apps). Finally you can write
    the exceptions to db, you can just serialize them and in your serialization
    routine write to the db. The main problem with this approach is if DB
    connectivity is what's throwing the excetion, then you may throw new ones
    and you probably won't be able to write them out. Finally you can use SMTP
    or Pop and mail the messages to yourself which is pretty decent for
    production but a bit slow for development and testing.

    Probably debug.Writeline and Assertions using Debug or Trace will work for
    giving you timely info as a developer . For other stuff you can write to
    the event logs or use one of the other approaches. HTH,

    Bill
    "Kshitij" <anonymous@disc ussions.microso ft.com> wrote in message
    news:273C5368-EEF8-4411-8E3E-77B4D7183F61@mi crosoft.com...[color=blue]
    > Hi,
    >
    > How to handle exceptions and show messages in a web application? In[/color]
    windows application we can create a log file and show the message on message
    box.What is the way to do it in a web application?[color=blue]
    >
    > Thanks in advance.[/color]


    Comment

    • William Ryan  eMVP

      #3
      Re: Exception handling in web applications

      Be very careful here! I was just at a TechNet discussion and the subject
      was Web Security and one of the biggest points they made was not exposing
      exceptions to users. Hackers will often try to break the app and gain info
      from the exception message. One fairly large company got one of their
      primary tables truncated and the attacker was able to do it by injection
      attacks coupled with info from the exception message which told him what to
      hit.

      You have a few choices as far as developer exceptions go. First off, I'd
      recommend against using MessageBoxes, use assertions and in the try catch
      block use Debug.Assert(fa lse, ex.ToString()); it'll give you a little more
      flexibility. Either way it's not going to happen with the web. You could
      serialize your exceptions and write them to an XML file for one thing. Many
      times we use debug constants and set a place on the web server to write
      exceptions when it's in debug mode. Then when we switch to release, it stops
      and all is good. YOu can also write to event logs although you'll need some
      increased permissions to do this and if your app throws a lot of exceptions,
      they can fill up quickly (although it takes a fair volume to do this to the
      point its a pain for most small to mid sized apps). Finally you can write
      the exceptions to db, you can just serialize them and in your serialization
      routine write to the db. The main problem with this approach is if DB
      connectivity is what's throwing the excetion, then you may throw new ones
      and you probably won't be able to write them out. Finally you can use SMTP
      or Pop and mail the messages to yourself which is pretty decent for
      production but a bit slow for development and testing.

      Probably debug.Writeline and Assertions using Debug or Trace will work for
      giving you timely info as a developer . For other stuff you can write to
      the event logs or use one of the other approaches. HTH,

      Bill
      "Kshitij" <anonymous@disc ussions.microso ft.com> wrote in message
      news:273C5368-EEF8-4411-8E3E-77B4D7183F61@mi crosoft.com...[color=blue]
      > Hi,
      >
      > How to handle exceptions and show messages in a web application? In[/color]
      windows application we can create a log file and show the message on message
      box.What is the way to do it in a web application?[color=blue]
      >
      > Thanks in advance.[/color]


      Comment

      • Cor Ligthert

        #4
        Re: Exception handling in web applications

        Hi Kshitjij

        Save them on your webserver in either the standard logging, a speciallogfile
        or in your database.

        And of course in a for standard users unreachable place.

        Cor


        Comment

        • Cor Ligthert

          #5
          Re: Exception handling in web applications

          Hi Kshitjij

          Save them on your webserver in either the standard logging, a speciallogfile
          or in your database.

          And of course in a for standard users unreachable place.

          Cor


          Comment

          Working...