StackExchange Exceptional How to setup for ASP.NET Web Form

984 Views Asked by At

As title, does anyone know how to setup StackExchange.Exceptional for asp.net web form

1

There are 1 best solutions below

0
On BEST ANSWER

I got answer from StackExchangeException github page: https://github.com/NickCraver/StackExchange.Exceptional/issues/82#issuecomment-280708220

Here is content:

ASP.NET Web Forms are certainly supported. Just configure your web.config file similar to this:

<configuration>
  <configSections>
    <section name="Exceptional" type="StackExchange.Exceptional.Settings, StackExchange.Exceptional"/>
  </configSections>
  <Exceptional applicationName="MyWebFormsApp">
    <!-- Error log store to use -->
    <ErrorStore type="SQL" connectionString="Data Source=.;Initial Catalog=Exceptions;Uid=Exceptions;Pwd=iloveerrors" />
  </Exceptional>
  <system.webServer>
    <modules>
      <add name="ErrorStore" type="StackExchange.Exceptional.ExceptionalModule, StackExchange.Exceptional" />
    </modules>
    <handlers>
      <add name="Exceptional" path="exceptions.axd" verb="POST,GET,HEAD" type="StackExchange.Exceptional.HandlerFactory, StackExchange.Exceptional" preCondition="integratedMode" />
    </handlers>
  </system.webServer>
</configuration>

Here's an explanation of the relevant parts and what needs to be configured. 1: The added entry in defines how to understand the section below. It pretty much should look exactly like that.

2: The section is what directly configures Exceptional.

3: The applicationName can be any name you want. It's there so that you could have multiple applications/websites storing errors in the same spot.

4: The ErrorStore is where you tell Exceptional where to save the errors. Assuming you want to store them in SQL Server, you just specify "SQL" for the type and give it the connectionString to connect to your database. (Don't forget to run the SQL script for adding the table to your database.)

5: The section adds the ExceptionalModule, which creates a hook for grabbing any unhandled exceptions and logging them.

6: The section adds an entry that maps the path "exceptions.axd" to the HandlerFactory, which will allow you to view the logged exceptions when you go to that path.

This is just a quick and easy basic setup. There's other ways of configuring everything and there's other things that can be added (like emailing errors). But this should at least get you started. Be sure to also check the Wiki pages.