Asp.net Custom Error Page Send Email
Contents |
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 asp.net error handling questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle>
Asp.net Error Handling Best Practices
Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ customerrors / 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 elmah / 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
Server Error In '/' Application.
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 » Web Development » ASP.NET » General Tip/TrickBrowse CodeStatsRevisions (8)Alternatives (1) Comments (17) Add your ownalternative version Tagged as ASP.NET Stats 46.6K views21 bookmarked Posted 23 Sep 2011 Send ASP.NET formatted exception details via email Mohammad A Rahman, 9 Oct 2011 CPOL 4.95 (13 votes) 1 2 3 4 5 4.95/5 - 13 votesμ 4.95, σa 1.05 [?] Rate this: Please Sign up or sign in to vote. How to send ASP.NET formatted exception details via email Managing Exception/Error is a common task in any application. In ASP.NET, there are many ways to handle those errors or exceptions, for example, when an error or exception occurrs in an ASP.NET application, the system is going to send a formatted error message to specified developers or teams mentioned in the email list. The difference will be the body of the email will contain exactly the same formatted error as the ASP.NET generated one to display the error or exception details when occurred. For example, But when an ASP.
Websites Community Support ASP.NET Community Standup ForumsHelp Web Forms:Guidance Videos Samples Forum Books Open Source Older Versions - Getting Started Getting StartedGetting Started with ASP.NET 4.5 Web Forms and Visual Studio 20131. Getting Started with Web Forms and Visual Studio2. Create the Project3. Create the Data Access Layer4. UI and Navigation5. Display Data Items and Details6. Shopping Cart7. Checkout and Payment with PayPal8. Membership and Administration9. URL Routing10. ASP.NET Error HandlingIntroduction to ASP.NET Web FormsCreating a Basic Web Forms http://www.codeproject.com/Tips/259139/Send-ASP-NET-formatted-errors-details-via-Email Page in Visual Studio 2013Creating ASP.NET Web Projects in Visual Studio 2013Code Editing ASP.NET Web Forms in Visual Studio 2013ASP.NET Scaffolding in Visual Studio 2013ASP.NET Web Forms (dotnetConf 2014)Using Page Inspector for Visual Studio 2012 in ASP.NET Web FormsVisual Studio 2012 Hands On LabsWhat's New in ASP.NET and Web Development in Visual Studio 2012What's New in Web Forms https://www.asp.net/hosting/tutorials/displaying-a-custom-error-page-cs in ASP.NET 4.5Using Page Inspector in Visual Studio 2012Monitoring and TelemetryRoutingASP.NET 4 - RoutingASP.NET 4 - Defining RoutesASP.NET 4 - Constructing URLs from RoutesASP.NET 4 - Accessing URL Parameters in a PageJavaScript and Client FrameworksASP.NET 4 - Microsoft Ajax OverviewASP.NET AJAX Control Toolkit (maintained by DevExpress)Working with Data Getting Started with ASP.NET 4.5 Web FormsModel Binding and Web Forms in Visual Studio 20131. Retrieving and Displaying Data2. Updating, Deleting, and Creating Data3. Sorting, Paging, and Filtering Data4. Integrating JQuery UI Datepicker5. Using Query String Values to Filter Data6. Adding Business Logic LayerASP.NET 4 Web Forms - Validating User Input in a PageASP.NET 4 Web Forms - State ManagementASP.NET Data Access - Recommended ResourcesServer Data ControlsASP.NET 4 Data-Bound ControlsASP.NET 4 Data Source Controls OverviewASP.NET 4.5 Chart ControlRecommended Resources for ASP.NET Data AccessSecurity, Authentication, and Authorization Getting Started with ASP.NET 4.5 Web FormsASP.NET IdentityCreate a secure ASP.NET Web Forms app with user registration, email confirmation and password reset (C#)Create an ASP.NET Web Forms app with SMS Two-Factor Authentication (C#)OWIN and KatanaPerformanceUsing Asy
exception, for example, when an error or exception occurred in ASP.NET http://mohammad-rahman.blogspot.com/2011/09/send-aspnet-formatted-errors-details.html application, system is going to send formatted error message to specified developers or team mentioned in the email list. The difference will be the body of email will contain exactly same formatted error ASP.NET generated to display the error or exception details when occurred. asp.net error For example, But when an ASP.NET application goes into life, user should not experience to see the above error page where they should see custom error page which easy to understand. More information about is in here. So in here, this test application asp.net error handling will display default error page when there is an error occurred in the system and send an email formatted like above image. To do that need to add voidApplication_Error(objectsender,EventArgse) method into Global.asax.cs file, the code block is, void Application_Error(object sender, EventArgs e) { HttpUnhandledException httpUnhandledException = new HttpUnhandledException(Server.GetLastError().Message, Server.GetLastError()); SendEmailWithErrors(httpUnhandledException.GetHtmlErrorMessage()); }So GetHtmlErrorMessage() method of HttpUnhandledExceptionclass will do all the formatting stuff.The code block to send email is below,privatestaticvoidSendEmailWithErrors(stringresult){try{MailMessageMessage=newMailMessage();Message.To="Toaddress";Message.From="FROMaddressd";Message.Subject="Exceptionraised";Message.BodyFormat=MailFormat.Html;Message.Body=result;SmtpMail.SmtpServer="SMTPSeverAddress";SmtpMail.Send(Message);}catch(System.Web.HttpExceptionehttp){//Writeotheeventlog.}}To test it there is button on page which manually trigger an exception, the code for button is as below,protectedvoidbtnError_Click(objectsender,EventArgse) {thrownewException("ThisExceptionisraisedtotest"); }So now the system will display default error page when an exception occurred and send email with formatted exception de