I want to make All Methods about Error handling in asp.net
some one device me at using global.asax
what is global.asax?
how can i use it ?
thanks , for help
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mahesh ChandRank #1 · 393.3K reputationPosted Jan 27, 2010, 8:55 AM EST
The Global.asax file, also known as the ASP.NET application file, is an optional file that contains code for responding to application-level events raised by ASP.NET or by HttpModules. The Global.asax file resides in the root directory of an ASP.NET-based application. At run time, Global.asax is parsed and compiled into a dynamically generated .NET Framework class derived from the HttpApplication base class. The Global.asax file itself is configured so that any direct URL request for it is automatically rejected; external users cannot download or view the code written within it.
The ASP.NET Global.asax file can coexist with the ASP Global.asax file. You can create a Global.asax file either in a WYSIWYG designer, in Notepad, or as a compiled class that you deploy in your application's \Bin directory as an assembly. However, in the latter case, you still need a Global.asax file that refers to the assembly.
The Global.asax file is optional. If you do not define the file, the ASP.NET page framework assumes that you have not defined any application or session event handlers.
Read here more about this
Here is an article on how to use Global.asax:
http://asp.dotnetheaven.com/aspnet/doc/applications/globalasax.aspx
Andrew FensterRank #983 · 2K reputationPosted Jan 28, 2010, 7:58 PM EST
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
This method fires whenever there's an unhandled exception. So you can put code in this method to log the error, display an error message or do whatever else seems appropriate. That being said, you really should try to catch and handle errors long before they get to the Global.asax page. You can put try-catch blocks in individual methods. You can catch them at the page level. A very common technique is to write your own Page base class that catches errors and then make all your individual .aspx pages inherit from this base class. That's what I would recommend.
Here is an article that describes how to make your own custom base Page class and use it to handle errors. In most cases, this is the way to go.
http://www.codedigest.com/Articles/ASPNET/56_Using_Custom_BasePage_Class_in_ASPNet.aspx
Good luck to you.
Mageshwaran RRank #411 · 6.1K reputationPosted Nov 22, 2019, 5:42 AM EST