Global.asax.cs Error Handler
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies how to handle application error in global.asax in mvc of this site About Us Learn more about Stack Overflow the company
Global.asax Error Handling
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges global.asax application_error not firing Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: application error event in global asax Sign up Application_Error in global.asax not catching errors in WebAPI up vote 6 down vote favorite 1 For a project I am working on, one of the things we're implementing is something that we have code for in some of my teams older ASP.NET and MVC projects - an Application_Error exception catcher that dispatches an email to the development team with the
Application_error Web Api
exception experience and most relevant details. Here's how it looks: Global.asax: protected void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError(); string path = "N/A"; if (sender is HttpApplication) path = ((HttpApplication) sender).Request.Url.PathAndQuery; string args = string.Format("Path: {0}", path); // Custom code that generates an HTML-formatted exception dump string message = Email.GenerateExceptionMessage(ex, args); // Custom code that sends an email to the dev team. Email.SendUnexpectedErrorMessage("Some App", message); } One "minor" problem, though - when I intentionally have a part of the code throw an exception in order to test this mechanism... public static void GetMuffinsByTopping(string topping) { throw new Exception("Test Exception!", new Exception("Test Inner Exception!!!")); // Actual repository code is unreachable while this test code is there } The front-end JavaScript is immediately intercepting an HTTP 500 request, but the global.asax.cs code noted above is not being reached (I set a breakpoint on the first executing line of the method.) Question: In what way can I get the "old" Application_Error handler to dispatch error emails, so that our team's developers can more easily debug our application? c# asp.net-web-api error-reporting share|improve this question asked F
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 asp.net error handling best practices more about Stack Overflow the company Business Learn more about hiring developers or application_error mvc 5 posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community
Asp.net Mvc Global Error Handling
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Catching errors in Global.asax up vote 8 down vote http://stackoverflow.com/questions/28768715/application-error-in-global-asax-not-catching-errors-in-webapi 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"); } } } 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 http://stackoverflow.com/questions/10061837/catching-errors-in-global-asax 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 124k23196308 asked Apr 8 '12 at 9:36 Peuge 71511330 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 votes up vote 2 down vote Application_Error block can catch exception anytime between application life cycle. Application life cycle is parent of Session life cycle as you can understand there can be many sessions within a single application. Thus you may have HttpContext.Current null at certain errors occured before creating session or after expiring of sessions. If you wa
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 http://forums.asp.net/t/1505777.aspx?Error+Handling+in+global+asax Oct 27, 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 error handling in the 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