Hi all, is there a way to trap for this error?

Hi all,

I get this message on one of my websites when a user logs in, it happens very rarely - what I have on the page is two text boxes and a button which runs code to validate the user logging in against an access database, so nothing super fancy. I've added the solution posted here in to the web.config file, but there's no way for me to test if this error ever comes up, so I'd like to build in some kind of error trap if its possible?
Who is Participating?
global.asax is a file that sits in the root of your web app. It allows you to hook events such as a new session being created, errors occurring etc.

For a friendly error page, you could use the customErrors element in your web.config:

Add error pages to your application, ie. 404.aspx & 5xx.aspx

404.aspx would show a Page Not Found message
5xx.aspx would show a friendly message saying an error occured. You would also log the error in this page so you know what went wrong using the Server.GetLastError() method.

    <customErrors mode="RemoteOnly" defaultRedirect="/5xx.aspx" redirectMode="ResponseRewrite">
      <error statusCode="404" redirect="/404.aspx"/>

Open in new window

You can use the Application_Error in your Global.asax to get the error. Then just log it a text file.
ZoooinkAuthor Commented:
I don't have a global asax file?? What is the purpose of the file?

Also, how can a show a user friendly message instead of the standard error page that comes up??
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.