Peter Nordberg
asked on
Error handling in asp.net site
Hi,
I have this site where I want to redirect my errors to specific pages and also mail the error to a specific mail when it occurs. In order to do so I first altered my web.config like this:
Then I added the following code to Global.asax.
What am I missing?
Thanks for help!
Peter
I have this site where I want to redirect my errors to specific pages and also mail the error to a specific mail when it occurs. In order to do so I first altered my web.config like this:
<system.web>
<customErrors mode="Off" defaultRedirect="Customerrorpage.aspx">
<error statusCode="404" redirect="Error404.aspx" />
</customErrors>
</system.web>
Then I added the following code to Global.asax.
Sub Application_Error(sender As Object, e As EventArgs)
Dim objErr As Exception = Server.GetLastError().GetBaseException()
Dim err As String = "<br><b>Error in: </b>" + Request.Url.ToString() + "<br><b>Error Message: </b>" + objErr.Message.ToString() + "<br><b>Stack Trace:</b><br>" + objErr.StackTrace.ToString()
'Email sending method
Dim msg As New EmailMessage
'Dim path As String = "\\arkenmail\MailPickUp\"
msg.Server = "smtp.server"
msg.Username = "test@test.com"
msg.Password = "psw"
msg.From = "info@test.com"
msg.FromName = "ErrorPost"
msg.To = "mymail@test.com"
msg.Subject = "Error in code"
msg.Body = err
msg.CharSet = "utf-8"
msg.BodyFormat = aspNetEmail.MailFormat.Html
If msg.Send Then
End If
End Sub
Unfortunately none of the scenarios kicks in. When I have a 404 for example it doesn't redirect to the specified page.What am I missing?
Thanks for help!
Peter
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
please check whether the custom error page is located in right folder or some other resource is not found
ASKER
I've placed two the files in the root of the site.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've already tested that like so:
Open in new window
But still get the usual error message:HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Peter