Error Page Asp.net 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 Http404ErrorPage.aspx file. These HTTP 404 errors would occur if a request were made for an .aspx file, .asmx file, and so on and if the requested file did not exist. All other unhandled errors in ASP.NET files are directed to the DefaultRedirectErrorPage.aspx file. If static content files are not handled by ASP.NET, a request for a nonexiste
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 other. Join them; it only takes a minute: Sign up https://msdn.microsoft.com/en-us/library/bb397417.aspx Custom error in global.asax up vote 1 down vote favorite In my global.asax file, I have the following code: void Application_Error(object sender, EventArgs e) { Exception TheError = Server.GetLastError(); if (TheError is HttpException && ((HttpException)TheError).GetHttpCode() == 404) { Response.Redirect("~/404.aspx"); } else { Response.Redirect("~/500.aspx"); } } When I navigate to an non-existing page, I get the generic error page. I don't want anything pertaining http://stackoverflow.com/questions/25321794/custom-error-in-global-asax to custom error in the web.config because my plan is to add code to the global.asax file to log the exceptions. Is there a way to handle custom error with just the global.asax file? Thanks. c# asp.net share|improve this question edited Aug 15 '14 at 6:21 asked Aug 15 '14 at 5:48 frenchie 14.3k64185348 Are you using Cassini, or IISExpress? Which version of .NET? –Tieson T. Aug 15 '14 at 6:33 using webforms on .net 4.5 and whether it's on IIS or on my local machine the result is the same. –frenchie Aug 15 '14 at 6:34 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted EDIT: The answer is not obvious, but this seems to explain it: http://www.asp.net/web-forms/tutorials/deployment/deploying-web-site-projects/displaying-a-custom-error-page-cs If you scroll down a ways, you'll find this lovely tidbit: Note: The custom error page is only displayed when a request is made to a resource handled by the ASP.NET engine. As we discussed in the Core Differences Between IIS and the ASP.NET Development Server tutorial , the web server may handle certain requests itself. By
here for a quick overview of the site Help Center Detailed answers to any questions you might http://stackoverflow.com/questions/27688759/custom-error-using-global-asax-asp-net 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 http://www.codeproject.com/Articles/600466/ASP-NETplusApplicationplusErrorplusHandling 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 error page million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Custom Error using Global.asax asp.net up vote 3 down vote favorite I made an error; the page directs users in case of error in any applications within the website. I made Global.asax rather than using Webconfig. My question error page asp.net is : Is it possible to redirect user from Global.asax for those statusCodes "401", "404" and "500" in case of error rather than using Webconfig ? In other words, using Global.aspx rather than Webconfig !? I am just curious to know. Thank you c# asp.net share|improve this question edited Dec 29 '14 at 13:08 SandyShores 4811519 asked Dec 29 '14 at 12:19 Dodi 7416 It is possible, however I really don't see any value added...stackoverflow.com/questions/14822435/… –gustavodidomenico Dec 29 '14 at 12:23 using web.config is better just search on google for
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 about this article 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 » Web Development » ASP.NET » General ArticleBrowse CodeStatsRevisions (9)Alternatives Comments (37) Add your ownalternative version Tagged as HTMLC#VS2013ASP.NET Stats 112.4K views2.7K downloads90 bookmarked Posted 30 May 2013 ASP.NET Application Error Handling Daniel Miller, 26 Jan 2015 CPOL 4.95 (37 votes) 1 2 3 4 5 4.95/5 - 37 votesμ 4.95, σa 1.05 [?] Rate this: Please Sign up or sign in to vote. Application error handling in ASP.NET Download demo - 269.4 KB Introduction When an unhandled exception occurs in my application, I want my application to give the user a "graceful" response. Regardless of the error, I do not want the user to see an unfriendly technical error messages generated by IIS or ASP.NET. At the same time, I want to receive email notification for every unhandled exception. This article describes a simple and comprehensive solution to this problem. The Problem When I have no error handling configured for my application, my users might see any one of three different error pages, depending on the type of error. If a user requests a static resource that does not exist (for example, an HTML or JPG file), then the user sees the default HTTP error message generated by IIS: If a user