1.7. Adding the Custom Exception Handler to Your Own Site

Building this class library sure has been fun, but the fun's not over yet. Remember, the best part of this project is that, now that it's finished, you can use it in all your web sites!

Here, I'll present a quick checklist of steps to take to get it working, either in a brand-new or existing site.

  • Open the LD.ExceptionHandling project from the download folder, and compile it in release mode.

  • Pick up the LD.ExceptionHandling.dll file from the bin/Release folder of the compiled project, and drop it into the Bin folder of your own site.

  • Configure the application in web.config.

    • First, place the code from Listing 31 to register the <exceptionHandling> section.

    • Second, place the code from Listing 32 to register the ErrorModule class.

    • Third, specify the attributes you want in the <exceptionHandling> section.

  • You should configure the ASP.NET default exception handler in the <customErrors> section too.

  • If you're using the e-mail or SMS notification features, make sure that you've specified the correct host, port, and credentials for your e-mail server in the <mailSettings> section of web.config and have confirmed that you're able to send e-mails from your site successfully.

Example 31. Registering the <exceptionHandling> section
<configSections>
   <section
      name="exceptionHandling"
      type="LD.ExceptionHandling.ExceptionSection"
      requirePermission="false" />
</configSections>

Example 32. Registering the ErrorModule class
<httpModules>
   <add name="ErrorModule"
      type="LD.ExceptionHandling.ErrorModule,
         LD.ExceptionHandling, Culture=neutral"/>
</httpModules>

Finally, you need to prepare your error logging store to accept records.

  • If you specify Xml for the logging method, make sure to grant the ASP.NET account read/write/modify permissions on the folder that will hold your log file. By default, the App_Data folder is used, which is a good secure choice as it prevents the file from being directly served to the browser.

  • If you specify Database for logging, make sure to set up the required table. You can do that by running the CreateErrorTable.sql script against your database. This script is included with the download.

All in all, only a few minutes of work. That's really all there is to including a robust, configurable, and highly functional error handling, logging, and notification framework to your site.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.77.153