Asp.net Custom Error Page Get Exception
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have asp.net application_error Meta Discuss the workings and policies of this site About Us
Asp.net Error Handling
Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with
Exception Handling In Asp.net C#
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
Asp.net Error Page
like you, helping each other. Join them; it only takes a minute: Sign up Asp.net 4.0 : How to get exception details in custom error page? up vote 6 down vote favorite 1 We are using custom error provided by asp.net config setting. In entire application (PL/BLL/DAL) we are not using any try catch. So for asp.net error logging any exception in any layer application redirect user to custom error page set in custom error setting in config file. Now we want to log following information in log file before showing error page: - Date & time - Exception message & strack trace. - Page Name - Method Name - Method Parameter & values. Please help me how to collect above information in custom error page_load event?? Thanks, @Paul asp.net-4.0 custom-error-pages exception-logging share|improve this question asked Jul 11 '12 at 3:15 Paul 219924 add a comment| 2 Answers 2 active oldest votes up vote 11 down vote You can store error details in session and get them in custom error page. This code is in Global.asax: protected void Application_Error(object sender, EventArgs e) { Exception err = Server.GetLastError(); Session.Add("LastError", err); } void Session_Start(object sender, EventArgs e) { Session["LastError"] = ""; //initialize the session } Then in your error page load: protected void Page_Load(object sender, EventArgs e) { Exception err = Session["LastError"] as Exception; //Exception err = Server.GetLastErro
One games Xbox 360 games PC https://support.microsoft.com/en-us/kb/306355 games Windows games Windows phone games Entertainment All Entertainment Movies & TV Music Business & Education Business Students & http://www.codeproject.com/Tips/142251/Getting-the-last-error-in-a-custom-error-page educators Developers Sale Sale Find a store Gift cards Products Software & services Windows Office Free downloads & security asp.net error Internet Explorer Microsoft Edge Skype OneNote OneDrive Microsoft Health MSN Bing Microsoft Groove Microsoft Movies & TV Devices & Xbox All Microsoft devices Microsoft Surface All Windows PCs & tablets PC accessories Xbox & games Microsoft Band Microsoft asp.net error handling Lumia All Windows phones Microsoft HoloLens For business Cloud Platform Microsoft Azure Microsoft Dynamics Windows for business Office for business Skype for business Surface for business Enterprise solutions Small business solutions Find a solutions provider Volume Licensing For developers & IT pros Develop Windows apps Microsoft Azure MSDN TechNet Visual Studio For students & educators Office for students OneNote in classroom Shop PCs & tablets perfect for students Microsoft in Education Support Sign in Cart Cart Javascript is disabled Please enable javascript and refresh the page Cookies are disabled Please enable cookies and refresh the page CV: {{ getCv() }} English (United States) Terms of use Privacy & cookies Trademarks © 2016 Microsoft
Latest Articles Latest Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions View All Questions... C# questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Articles » General Programming » Programming Tips » General Tip/TrickBrowse CodeStatsRevisions (3)Alternatives (1) Comments (4) Add your ownalternative version Tagged as C#ASP Stats 16.3K views3 bookmarked Posted 3 Jan 2011 Getting the last error in a custom error page OriginalGriff, 5 Jan 2011 CPOL 4.33 (3 votes) 1 2 3 4 5 4.33/5 - 3 votesμ 4.33, σa 2.02 [?] Rate this: Please Sign up or sign in to vote. When you provide a custom error handler page, it is useful to be able to log what caused the problem, so that you can fix it. Server.GetLastError() will not return anything in the page, though... When you provide a custom error handler page, it is useful to be able to log what caused the problem, so that you can fix it. Normally, this is just a case of using Exception lastError = Server.GetLastError(); if (lastError == null) { ErrorLog("An error occurred, but no error information is available"); } else { ErrorLog(lastError.ToString()); } This fails however, because the redirect to the error page loses the error information. You can handle a Page Error event and pass the error through in a session variable, but that is a bit clunky, and means coding in your Master page and / or each actual page, plus the sessio