![]() cs file the event handlers of interest are defined in the file. ![]() The Global.asax file contains nothing but an directive that references the. With a WAP, the Global.asax is implemented as two separate files - Global.asax and. The contents and structure of the Global.asax file created by Visual Studio differ slightly based on whether you are using a Web Application Project (WAP) or Web Site Project (WSP). To create this file in your website, add a new item to the root of your website using the Global Application Class template with the name Global.asax.įigure 1: Add Global.asax To Your Web Application These HttpApplication events give the page developer a means to execute custom logic at the various points in the lifetime of a request.Įvent handlers for the HttpApplication events can be placed in a special file named Global.asax. For example, the HttpApplication class's BeginRequest event is raised at the start of every request its AuthenticateRequest event is raised when a security module has identified the requestor. The Error event is one of many events in the HttpApplication class that are raised at certain stages in the HTTP pipeline during the lifetime of a request. But how do you create an event handler for the Error event? Given that the ASP.NET runtime raises its Error event whenever an unhandled exception occurs, it follows that the code for logging the error's details would go in an event handler. ![]() If you want to run some code when the visitor clicks a particular Button, you create an event handler for that Button's Click event and put your code there. As an ASP.NET developer you are accustomed to thinking in terms of events. Executing Code When The ErrorEvent Is RaisedĮvents provide an object a mechanism for signaling that something interesting has occurred, and for another object to execute code in response. The next two tutorials provide an overview of two such libraries. In cases where you only need to log the exception and notify a developer, using an error logging library is the way to go. The information examined in this tutorial is most useful if you need to process unhandled exceptions in some unique or customized manner. The two tutorials following this one explore error logging libraries that, after a bit of configuration, will automatically notify developers of runtime errors and log their details. This tutorial shows how to access the details of an unhandled exception so that they can be logged and a developer notified. Furthermore, the error's details should be logged so that the error can be examined and diagnosed at a later point in time. When an error occurs in an application in production, it is important that the developers are notified of the error so that they can unearth the cause of the exception and address it. Using a human-friendly custom error page that matches the look and feel of the site is preferred to the default Runtime Error YSOD, but displaying a custom error page is only one part of a comprehensive error handling solution. In the preceding tutorial we configured the application to use a custom error page for remote users and the Exception Details YSOD for users visiting locally. There are three different types of error pages: the Runtime Error Yellow Screen of Death (YSOD) the Exception Details YSOD and custom error pages. When an unhandled exception occurs in an ASP.NET application, it bubbles up to the ASP.NET runtime, which raises the Error event and displays the appropriate error page. This tutorial provides an overview of how ASP.NET processes runtime errors and looks at one way to have custom code execute whenever an unhandled exception bubbles up to the ASP.NET runtime. When a runtime error occurs on a web application in production it is important to notify a developer and to log the error so that it may be diagnosed at a later point in time. View or download sample code ( how to download)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |