473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Asp.net custom errors not working

19
I'm trying to set up custom errors for asp.net in webconfig/global.asax on Server 2003, IIS 6. Got it working find for .aspx pages but not for any htm or html pages. So I found the article describing how to open IIS manager, click configuration, copy path for .aspx extension and add one for .htm Did that.

Restarted website: Now I get the blank white page explaining there's a problem but not the 404 page not found
Restarted web services: same thing

Anybody got any tips?

Janet
Mar 16 '10 #1
5 3163
CroCrew
564 Expert 512MB
What types of errors are you looking to trap in the HTML pages?

CroCrew~
Mar 24 '10 #2
Frinavale
9,735 Expert Mod 8TB
I'm assuming that the OP wants to trap any error and send them to a custom "error" page. I've tried this and have never fully been successful (sometimes it works and sometimes it doesn't) so I am very curious to find out how this problem was solved.


-Frinny
Mar 25 '10 #3
CroCrew
564 Expert 512MB
What "programming" errors would be trapped in an HTML page? I know how to trap logical errors on an asp/aspx page. I just don’t know what error would be thrown in a markup language page? Maybe I am over thinking this one..

CroCrew~
Mar 25 '10 #4
CroCrew
564 Expert 512MB
This is what I use for my custom errors within my applications.

In the “Global.asax” I add the following code:
Expand|Select|Wrap|Line Numbers
  1.     Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
  2.         ' Code that runs when an unhandled error occurs
  3.         Server.Transfer("Errors.aspx")
  4.     End Sub
  5.  
Here is a slimed down version of my “Errors.aspx” page:
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Errors.aspx.vb" Inherits="Errors" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.     <head id="Head1" runat="server">
  5.         <title></title>
  6.     </head>
  7.     <body>
  8.        <form>
  9.             <div>
  10.                 <asp:Label ID="LblMessagesAndErrors" runat="server" ForeColor="#e10000" Font-Bold="true" />
  11.             </div>
  12.         </form>
  13.     </body>
  14. </html>
  15.  
Here is a slimed down version of my “Errors.aspx.vb” page:
Expand|Select|Wrap|Line Numbers
  1. Partial Class Errors
  2.     Inherits System.Web.UI.Page
  3.     Dim MailFunctions As MailMan = New MailMan
  4.  
  5.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.         Dim errMessage As String = ""
  7.         Dim errorCode As String = "n/a"
  8.         Dim appException As System.Exception = Server.GetLastError()
  9.  
  10.         If (TypeOf (appException) Is HttpException) Then
  11.             Dim checkException As HttpException = CType(appException, HttpException)
  12.             errorCode = checkException.GetHttpCode
  13.             Select Case checkException.GetHttpCode
  14.                 Case 403
  15.                     errMessage &= "Error 777." & checkException.GetHttpCode & ": You are not allowed to view that page."
  16.                 Case 404
  17.                     errMessage &= "Error 777." & checkException.GetHttpCode & ": The page you have requested can't be found."
  18.                 Case 408
  19.                     errMessage &= "Error 777." & checkException.GetHttpCode & ": The request has timed out."
  20.                 Case 500
  21.                     errMessage &= "Error 777." & checkException.GetHttpCode & ": The server can't fulfill your request."
  22.                 Case Else
  23.                     errMessage &= "Error 777." & checkException.GetHttpCode & ": The server has experienced an error."
  24.             End Select
  25.         Else
  26.             errMessage &= "Error 777.0.000: The server has experienced an error."
  27.         End If
  28.  
  29.         LblMessagesAndErrors.Text = errMessage & "<br /><p>We are sorry for this inconvenience.</p><p>Please try back.</p>"
  30.  
  31.         Dim errEmailMessage As String = "<br/ >&nbsp;<br/ >" & Request.UrlReferrer.ToString() & "<br/ >&nbsp;<br/ >" & Now()
  32.  
  33.         Try
  34.             MailFunctions.SendEmail("CroCrew@None.com", "[~~~] ERROR www.MySite.com ERROR [~~~]", "[" & errorCode & "] " & appException.ToString & errEmailMessage)
  35.         Catch ex As Exception
  36.             ' just catching.
  37.         End Try
  38.  
  39.         Server.ClearError()
  40.     End Sub
  41.  
  42. End Class
  43.  
Every time an error outside of a try/catch is thrown it goes to this Error page and an email gets sent to me with information that I can use to start debugging the problem. Also, if the “Case Else” is used within the “Select Case checkException.GetHttpCode” I then can add to that case statement a new code if I want too.

I should say that I have a class that handles my sending of email called “MailMan”.

This along with trapping my code within “try/catch”s seems to handle all my custom error handling.

Hope this helps,
CroCrew~
Mar 25 '10 #5
Frinavale
9,735 Expert Mod 8TB
There's a setting in the web.config file that you can configure so that whenever an error occurs the user is directed to a custom error page.

You can also use the global.asax file to trap any errors that cannot be handled by your page code ...and in there you can manually redirect the user to a friendly custom error page.

I think the problem happens with how the server is configured because sometimes the server ignores the web.config's settings to redirect to custom error pages and it uses its own default pages.

I'm pretty sure it's a server configuration but I am not a very good administrator so I don't know the answer....

Especially with regards to this question because HTML pages are not really part of an ASP.NET application....I mean: I have no idea how to configure an ASP.NET website (or the server hosting the website) to know to redirect to an error page if the user is trying to access an HTML page.



-Frinny
Mar 25 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mark Aurit | last post by:
I have an intranet application that uses w2k Integrated Windows Authentication to authenticate users. We now have a situation where people will be accessing it who are on our network but will not...
4
by: Jon Spivey | last post by:
Hi, I've set up a custom error like this <customErrors mode="On" defaultRedirect="ErrorPage.aspx"> <error statusCode="404" redirect="error404.aspx" /> </customErrors> So requests for...
2
by: Matt | last post by:
Hello all, The app we are working on uses custom errors extensively to provide friendly error pages to users whilst logging the actual exceptions behind the scenes. However.... We are now...
0
by: Ranv | last post by:
Is it possible to use web.config to handle 404 Page Not Found errors, and application level custom errors to handle all other errors? I suppose I would have to make sure that I don't call...
0
by: Ranv | last post by:
Is it possible to use web.config to handle 404 Page Not Found errors, and application level custom errors (in global.asax) to handle all other errors? I suppose I would have to make sure that I...
2
by: Jason | last post by:
I want to raise custom errors. For instance, when my File class tries to copy a file, I check to make sure the file is available (by trying to get an exclusive lock on it). I try for a specific...
8
by: Mark A. Sam | last post by:
Hello I am working locally with Visual Web Developer 2005 Express. Before I even installed it, the information from Microsoft was that you could FTP it to a remote site and it should work. The...
0
by: gilly3 | last post by:
I'm coming across all kinds of frustration implementing custom errors in ASP.NET 1.1. First, 401 - Authorization Failed My application uses Windows Integrated Authentication, and restricts...
0
by: craigkenisston | last post by:
I want to be able to turn on and off the custom errors mode, in order I can do something like: http://www.mysite.com/?debug=true And then read the parameter, turn "off" the custom errors so I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.