NickCraver / StackExchange.Exceptional

Error handler used for the Stack Exchange network
https://nickcraver.com/StackExchange.Exceptional/
Apache License 2.0
860 stars 170 forks source link

[Question] Support ASP.NET WebForm #82

Closed minhhungit closed 7 years ago

minhhungit commented 7 years ago

Hi team, It looks we do not support asp.net web form, if we support it, can anyone please show me how to implement ?

CptRobby commented 7 years ago

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.

minhhungit commented 7 years ago

@CptRobby Thank you for spending time with me. It worked 👍