Application Error Handling In Global.asax
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. MSDN Library MSDN Library MSDN Library MSDN Library Design Tools Development Tools and Languages Mobile and Embedded Development .NET Development Office development Online Services Open Specifications patterns & practices Servers and Enterprise Development Speech Technologies Web Development Windows Desktop App Development TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. Complete Example for Error Handlers Other Versions Visual Studio 2010 .NET Framework 4 Visual Studio 2008 This code example includes elements for both page-level and application-level exception handling. Code Example Files The example consists of the following files: Web.config Global.asax Default.aspx ExceptionUtility (to be put in the App_Code folder) GenericErrorPage.aspx HttpErrorPage.aspx Http404ErrorPage.aspx DefaultRedirectErrorPage.aspx Web.config The following example shows the Web.config file. The customErrors section specifies how to handle errors that occur with file types that are mapped to ASP.NET, such as .aspx, .asmx, and .ashx files. (In IIS 6.0 and in IIS 7.0 in classic mode, static content files such as .html and .jpg files are not mapped to ASP.NET.) The settings in the example customErrors section cause any unhandled HTTP 404 (file not found) errors to be directed to the Http4
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each https://msdn.microsoft.com/en-us/library/bb397417.aspx other. Join them; it only takes a minute: Sign up Catching errors in Global.asax up vote 8 down vote favorite 2 I have the following in my Global.aspx which is meant for handling errors: void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); if (exception != null) { //Log if (HttpContext.Current.Server != null) { HttpContext.Current.Server.Transfer("/siteerror.aspx"); } } http://stackoverflow.com/questions/10061837/catching-errors-in-global-asax } This works for the most part, but sometimes does not get into Server.Transfer. For some reason HttpContext.Current.Server is null. I figured out where this happens: when errors occur in a user control and in my business logic classes. Am I missing something here? Thanks c# asp.net error-handling share|improve this question edited Apr 8 '12 at 11:43 svick 123k23194304 asked Apr 8 '12 at 9:36 Peuge 69311330 2 Any reason not using Response.Redirect rather? –leppie Apr 8 '12 at 9:41 1 Where in global.asax is this? –Marc Gravell♦ Apr 8 '12 at 9:42 @leppie I did not add this so not entirely sure why the previous person chose Server.Transfer, it shouldn't make a difference though should it? –Peuge Apr 8 '12 at 9:53 @MarcGravell I have updated the question to reflect this. –Peuge Apr 8 '12 at 9:54 Earlier you use Server.blah - does Server.Transfer(...) not work? (no HttpContext.Current) –Marc Gravell♦ Apr 8 '12 at 9:56 add a comment| 2 Answers 2 active oldest v
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/General ASP.NET/MVC/Error Handling in global.asax Error Handling in global.asax [Answered]RSS 8 replies Last post Oct 27, http://forums.asp.net/t/1505777.aspx?Error+Handling+in+global+asax 2011 09:51 AM by Robs030 ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Related Links GuidanceSamplesVideos Reply jackh None 0 Points 9 Posts Error Handling in global.asax Dec 18, 2009 03:50 PM|jackh|LINK Hi all, I'm currently trying to centralize error handling in the application error global.asax in my asp.net MVC app. It has the following code to display a custom Error view in the default location (~/Views/Shared/Error.aspx) without using the HandleError attribute in the Controllers and specifying the