• Increase font size
  • Default font size
  • Decrease font size

How to add simple Error logging to an ASP.NET application

E-mail Print PDF

When building an enterprise application, many would recommend using Microsoft's Enterprise Library for error logging.  If you are already using Enterprise Library in your application, then you may want to go that route.  For applications where simple error/exception logging is needed, I would personally recommend using ELMAH (Error Logging Modules and Handlers for ASP.NET).  Adding ELMAH to your application is very simple to do, and gains you the following features:

  • Logging of nearly all unhandled exceptions.
  • A web page to remotely view the entire log of recoded exceptions.
  • A web page to remotely view the full details of any one logged exception, including colored stack traces.
  • In many cases, you can review the original yellow screen of death that ASP.NET generated for a given exception, even with customErrors mode turned off.
  • An e-mail notification of each error at the time it occurs.
  • An RSS feed of the last 15 errors from the log.

Here I will walk you through quickly adding ELMAH to your application.  For this example, I will be logging errors to a Microsoft SQL database table, but the tool is configurable to several different datasources (MS SQL, MS SQL CE, MS Access, Oracle, SQLite, XML Files, MySQL, PostgreSQL).

  1. First, download the Core Binary and MS SQL Server DDL Script from the project website.
  2. Now you will need to execute the DDL script against your application's database (or a different one if you desire).  This script will create the logging table and a few stored procedures.
  3. Next, extract the Core Binary .zip file and drop the Elmah.dll file into your website's Bin directory.
  4. Now you will add a few lines to your application's web.config (see images below).  This configures ELMAH to log application execeptions.
    web config entries
    elmah web config entries
  5. In this case, I didn't want all site users to be able to view the error log.  So, I added the following to a web.config file in the /Admin directory of my application.  If you wanted all users to access the error log, you would put this in your root web.config file.
    elmah web config entries

Now to view your errors you would view the page http://[websitename]/elmah.axd (even though this file does not physically exist).  In this case, I wanted the errors viewable only to admins, so the URL would be http://[websitename]/admin/elmah.axd.  Here is a snapshot of the error page you will see:

elmah error page example

There you have it.  Simple Exception logging for your ASP.NET site using ELMAH. 




jQuery Error in ASP.NET website

E-mail Print PDF

I felt it necessary to share this information in hopes it saves someone else time and hassle.  I was recently working on an ASP.NET website for a client that made use of jQuery and jQueryUI.  The site worked fine when I referenced the jQuery files on the CDN (see Snippet 1 below).

Code Snippet 1.

javascript cdn reference

There were concerns about the website linking to externally hosted scripts, so I needed to download and reference the jQuery files (jquery-1.4.4.min.js, jquery-ui-1.8.7.custom.min.js) locally.  When I would reference the jQuery files locally (see Snippet 2),

Code Snippet 2.

javascript local reference

The site would break and produce the following error:

Microsoft JScript runtime error: object expected

I found many references to this error when searching the net, but they all referenced the PATH of the jQuery files and making sure it was correct.  I saw many solutions to map the PATH at run time, but no matter what the error persisted. From all the forum posts I read, it seems like many others could not resolve their issue unless they reference the files on CDN (Snippet 1 above).

After I realized the issue I had, it was obvious, but it took my some time to come to this conclusion.  I was restricting site access to unauthenticated users and redirecting to a login page (the login page was using jQuery functionality).  Using the ASP.NET Configuration tool, I blocked access to all site files except the login page (web config entry below).

This in effect was restricting access to the local jQuery files when an unauthenticated user visited the login page, causing the "object expected" error.   The solution to this is granting access to the directory holding the scripts.  I accomplished this by creating a new web.config file with the text below and placing it in the scripts directory.   

It is also noteworthy to mention the same condition can apply if you are using master pages and external CSS files.  If your login page references these items, anonymous users must have access to them.  I hope I am able to help someone out by posting this article.  If you have any questions, feel free to post them in the comments below or in the forum.  Good Luck!

How to add Simple Error Alerting to an SSIS package

E-mail Print PDF

If you using SSIS to move data around, you may have jobs where error notifications can't wait until the next day.  It is extremely simple to add email/paging/text alerts to your SSIS package.  Here is how to add simple error alerting to your SSIS package.  Note this process is detailed for the MS SQL 2005 version of SSIS.

1.  Click in the open space in the Control Flow designer.

 2.  Click the Event Handlers tab in your SSIS package.




How to add Simple Logging to an SSIS Package

E-mail Print PDF

If you using SSIS to move data around, you will probably want to log package start/stop times and any errors that occur. This is much easier to setup than you might.  The first time you run a package with logging enable, SSIS will even create the log table for you! It just requires create table permission in the database you choose.  So without further ado, here is how to add simple logging to your SSIS package.  Note this process is detailed for the MS SQL 2005 version of SSIS.

1) Open package and right-click in the open space of the Control Flow tab.  Click Logging…



ASP.NET Menu control doesn't display properly in Chrome/Safari

E-mail Print PDF

There is an issue with the current versions of Chrome and Safari browsers that can cause the ASP.NET menu control to not render properly.  If you are interested in understanding the how and why behind this, there is a great forum post here that describes the issue in more detail.  If you are like me and need to resolve the issue now so your site displays properly, here is a quick fix for the problem.

You need to put the following code into the Load event of your page's (or master page's) code behind file:

If Request.UserAgent.IndexOf("AppleWebKit") > 0 Then


End If

There may be other solutions to this issue, but this appears to be one of the simpler fixes.  Hope this helps!

  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  3 
  •  4 
  •  5 
  •  Next 
  •  End 
  • »

Page 1 of 5

Recommended Web Hosting

Featured FREE Resource:

Featured FREE Resource: