By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,436 Members | 2,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,436 IT Pros & Developers. It's quick & easy.

Error handling not working

P: n/a
This has been driving me crazy.

I have been trying to get the error handling working on my system and can
get parts of it working and others won't work at all.

I found that you can't access session variables from Application_Error
event, but I need to so I don't need to set up traces to see what they are
during an error. I am emailing the error condition to myself when it
happens.

So I moved the code to one of my error pages and it works fine if called
directly. So I added this code to my Application_Error routine:

Sub Application_Error(Sender As Object, E as EventArgs)
response.Redirect("/PageError.aspx")
End Sub

And it goes fine to my error page which emails my session variables to me,
but when I try to do:

Dim exception As Exception = Server.GetLastError()

I get nothing. I assume the Application_Error routine cleared it.

I then tried to comment out the Application_Error code so it would go to the
CustomErrors in my webconfig file:

<customErrors defaultRedirect="PageUnavailable.aspx" mode="Off" />

but the page is never called - it goes to the MS Error page. If Change mode
to "On",

<customErrors defaultRedirect="PageUnavailable.aspx" mode="On" />

I get the following page:

************************************************** *******************
Runtime Error
Description: An application error occurred on the server. The current custom
error settings for this application prevent the details of the application
error from being viewed remotely (for security reasons). It could, however,
be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable
on remote machines, please create a <customErrors> tag within a "web.config"
configuration file located in the root directory of the current web
application. This <customErrors> tag should then have its "mode" attribute
set to "Off".
<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom
error page by modifying the "defaultRedirect" attribute of the application's
<customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
************************************************** **********************************

I also tried setting up a Page_Error in my program and it never gets called.

I don't understand why this is a problem.

Tom
Feb 22 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Tom,
you want to do this:

Exception ex= Server.GetLastError().GetBaseException()

at this point, if you want, you could possibly even store the exception in
Session and then do your redirect.
GetBaseException retrieves the "real" innerException object.

Here's a pretty good article with some more ideas:
http://www.developer.com/net/asp/article.php/961301

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"tshad" wrote:
This has been driving me crazy.

I have been trying to get the error handling working on my system and can
get parts of it working and others won't work at all.

I found that you can't access session variables from Application_Error
event, but I need to so I don't need to set up traces to see what they are
during an error. I am emailing the error condition to myself when it
happens.

So I moved the code to one of my error pages and it works fine if called
directly. So I added this code to my Application_Error routine:

Sub Application_Error(Sender As Object, E as EventArgs)
response.Redirect("/PageError.aspx")
End Sub

And it goes fine to my error page which emails my session variables to me,
but when I try to do:

Dim exception As Exception = Server.GetLastError()

I get nothing. I assume the Application_Error routine cleared it.

I then tried to comment out the Application_Error code so it would go to the
CustomErrors in my webconfig file:

<customErrors defaultRedirect="PageUnavailable.aspx" mode="Off" />

but the page is never called - it goes to the MS Error page. If Change mode
to "On",

<customErrors defaultRedirect="PageUnavailable.aspx" mode="On" />

I get the following page:

************************************************** *******************
Runtime Error
Description: An application error occurred on the server. The current custom
error settings for this application prevent the details of the application
error from being viewed remotely (for security reasons). It could, however,
be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable
on remote machines, please create a <customErrors> tag within a "web.config"
configuration file located in the root directory of the current web
application. This <customErrors> tag should then have its "mode" attribute
set to "Off".
<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom
error page by modifying the "defaultRedirect" attribute of the application's
<customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
************************************************** **********************************

I also tried setting up a Page_Error in my program and it never gets called.

I don't understand why this is a problem.

Tom

Feb 22 '06 #2

P: n/a
That will get me the last error, but I am trying to get all the errors and
am looping through the innerException object. The GetBaseException also
gets me the last one, which would be fine. But I found that the error
response I get back is unreadable.

If I don't do the Application_Error, I get this error:

************************************************** *****************
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'SearchType' is not declared.

Source Error:

Line 89: Else
Line 90: 'We aren't dealing with an array, so just display the
variable
Line 91: if
SearchType.IndexOf(Session.Contents(strName).GetTy pe.ToString()) >= 0 then
Line 92: trace.warn(strName & " - " & Session.Contents(strName) & "
" & Session.Contents(strName).GetType.ToString)
Line 93: else

Source File:
C:\Inetpub\wwwroot\staffingworkshop\ADMINISTRATION \showExceptions.aspx
Line: 91

************************************************** *****************

If I do the following:

************************************************** *****************
Sub Application_Error(Sender As Object, E as EventArgs)
Dim exception As Exception = Server.GetLastError().GetBaseException()
Dim ErrorString as String

While Not exception Is Nothing
ErrorString &= "Source: " & exception.Source & vbCrLf & _
"Message: " & exception.Message & vbCrLf & _
"Stack Trace: " & vbCrLf & exception.StackTrace & vbCrLf &
vbCrLf
exception = exception.InnerException
End While

Dim MyMessage as New MailMessage
MyMessage.To = tf*@ftsos.com
MyMessage.From = "tf*@ftsos.com"
MyMessage.Subject = "Unhandled ASP.Net Error"
MyMessage.Body = vbCrLf & vbCrLf & "An Error was Generated on " & now &
vbCrLf & vbCrLf & _
"To see a list of Errors:
HTTP:\\www.staffingworkshop.com\administration\sho wExceptions.aspx" & vbCrLf
& vbCrLf & _
"Page: " & HTTPContext.Current.Request.Url.ToString() & vbCrLf &
vbCrLf & ErrorString

SmtpMail.SmtpServer = Application("MailServer")
SmtpMail.Send(MyMessage)

Context.ClearError()
response.Redirect("/PageError.aspx")
End Sub
************************************************** *****************

I get the following results:

************************************************** ******************
An Error was Generated on 2/21/2006 5:39:25 PM

To see a list of Errors:
HTTP:\\http://www.staffingworkshop.com\admi...xceptions.aspx

Page: http://www.staffingworkshop.com/ADMI...xceptions.aspx

Source: System.Web
Message: External component has thrown an exception.
Stack Trace:
at
System.Web.Compilation.BaseCompiler.ThrowIfCompile rErrors(CompilerResults
results, CodeDomProvider codeProvider, CodeCompileUnit sourceData, String
sourceFile, String sourceString)
at System.Web.Compilation.BaseCompiler.GetCompiledTyp e()
at System.Web.UI.PageParser.CompileIntoType()
at System.Web.UI.TemplateParser.GetParserCacheItemThr oughCompilation()
************************************************** ******************

If I take out the GetBaseException():

Dim exception As Exception = Server.GetLastError().GetBaseException()

I get

************************************************** *********************
An Error was Generated on 2/21/2006 5:41:49 PM

To see a list of Errors:
HTTP:\\http://www.staffingworkshop.com\admi...xceptions.aspx

Page: http://www.staffingworkshop.com/ADMI...xceptions.aspx

Source: System.Web
Message: External component has thrown an exception.
Stack Trace:
at System.Web.UI.TemplateParser.GetParserCacheItemInt ernal(Boolean
fCreateIfNotFound)
at System.Web.UI.TemplateParser.GetParserCacheItemWit hNewConfigPath()
at System.Web.UI.TemplateParser.GetParserCacheItem()
at
System.Web.UI.TemplateControlParser.CompileAndGetP arserCacheItem(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.TemplateControlParser.GetCompiledIns tance(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.PageParser.GetCompiledPageInstanceIn ternal(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.PageHandlerFactory.GetHandler(HttpCo ntext context,
String requestType, String url, String path)
at System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, String path, String pathTranslated, Boolean useAppConfig)
at
System.Web.MapHandlerExecutionStep.System.Web.Http Application+IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)

Source: System.Web
Message: External component has thrown an exception.
Stack Trace:
at
System.Web.Compilation.BaseCompiler.ThrowIfCompile rErrors(CompilerResults
results, CodeDomProvider codeProvider, CodeCompileUnit sourceData, String
sourceFile, String sourceString)
at System.Web.Compilation.BaseCompiler.GetCompiledTyp e()
at System.Web.UI.PageParser.CompileIntoType()
at System.Web.UI.TemplateParser.GetParserCacheItemThr oughCompilation()

************************************************** *********************

Either way there is nothing like: BC30451: Name 'SearchType' is not
declared.

Where do you get that?

These message are pretty useless without it.

Thanks,

Tom

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:8C**********************************@microsof t.com...
Tom,
you want to do this:

Exception ex= Server.GetLastError().GetBaseException()

at this point, if you want, you could possibly even store the exception in
Session and then do your redirect.
GetBaseException retrieves the "real" innerException object.

Here's a pretty good article with some more ideas:
http://www.developer.com/net/asp/article.php/961301

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"tshad" wrote:
This has been driving me crazy.

I have been trying to get the error handling working on my system and can
get parts of it working and others won't work at all.

I found that you can't access session variables from Application_Error
event, but I need to so I don't need to set up traces to see what they
are
during an error. I am emailing the error condition to myself when it
happens.

So I moved the code to one of my error pages and it works fine if called
directly. So I added this code to my Application_Error routine:

Sub Application_Error(Sender As Object, E as EventArgs)
response.Redirect("/PageError.aspx")
End Sub

And it goes fine to my error page which emails my session variables to
me,
but when I try to do:

Dim exception As Exception = Server.GetLastError()

I get nothing. I assume the Application_Error routine cleared it.

I then tried to comment out the Application_Error code so it would go to
the
CustomErrors in my webconfig file:

<customErrors defaultRedirect="PageUnavailable.aspx" mode="Off" />

but the page is never called - it goes to the MS Error page. If Change
mode
to "On",

<customErrors defaultRedirect="PageUnavailable.aspx" mode="On" />

I get the following page:

************************************************** *******************
Runtime Error
Description: An application error occurred on the server. The current
custom
error settings for this application prevent the details of the
application
error from being viewed remotely (for security reasons). It could,
however,
be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be
viewable
on remote machines, please create a <customErrors> tag within a
"web.config"
configuration file located in the root directory of the current web
application. This <customErrors> tag should then have its "mode"
attribute
set to "Off".
<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom
error page by modifying the "defaultRedirect" attribute of the
application's
<customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="RemoteOnly"
defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
************************************************** **********************************

I also tried setting up a Page_Error in my program and it never gets
called.

I don't understand why this is a problem.

Tom

Feb 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.