PC Review


Reply
Thread Tools Rate Thread

Custom Errors Not Working

 
 
=?Utf-8?B?RGVtZXRyaQ==?=
Guest
Posts: n/a
 
      23rd Aug 2006
I posted this question about a week or so ago. I never got any replies so
please forgive me if you have already read this question.

I have the following in my web config file:

<customErrors mode="RemoteOnly" defaultRedirect="Error.aspx" />

Here is the code in the Error.aspx:

protected void Page_Load(object sender, EventArgs e)
{
Exception err = Server.GetLastError().GetBaseException();

this.lblMessage.Text = err.ToString();
}

If mode is set to RemoteOnly I still get the yellow screen of death.
If mode is set to Off I still get the yellow screen of death.
If mode is set to On I get the yellow screen of death that tells me to set
the mode to RemoteOnly or Off to see the actual error message.

Why the heck doesn't it direct to my Error.aspx page and show the error that
way?


--
-Demetri
 
Reply With Quote
 
 
 
 
Juan T. Llibre
Guest
Posts: n/a
 
      23rd Aug 2006
re:
> Why the heck doesn't it direct to my Error.aspx page and show the error that way?


Any unhandled exception is captured by Application_Error.

What does your Application_Error sub/void in global.asax have ?

You should have something like :

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Server.Transfer("Error.aspx")
End Sub



Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Demetri" <(E-Mail Removed)> wrote in message
news:A92CA73C-2AD6-4A65-A5B7-(E-Mail Removed)...
>I posted this question about a week or so ago. I never got any replies so
> please forgive me if you have already read this question.
>
> I have the following in my web config file:
>
> <customErrors mode="RemoteOnly" defaultRedirect="Error.aspx" />
>
> Here is the code in the Error.aspx:
>
> protected void Page_Load(object sender, EventArgs e)
> {
> Exception err = Server.GetLastError().GetBaseException();
>
> this.lblMessage.Text = err.ToString();
> }
>
> If mode is set to RemoteOnly I still get the yellow screen of death.
> If mode is set to Off I still get the yellow screen of death.
> If mode is set to On I get the yellow screen of death that tells me to set
> the mode to RemoteOnly or Off to see the actual error message.
>
> Why the heck doesn't it direct to my Error.aspx page and show the error that
> way?
>
>
> --
> -Demetri



 
Reply With Quote
 
=?Utf-8?B?RGVtZXRyaQ==?=
Guest
Posts: n/a
 
      23rd Aug 2006
The Application_Error sub/void in global.asax has nothing. I didn't think it
needed any code since the customErrors section has an attribute for the
defaultRedirect, what is the point in this if I still need to write code to
do it in the Application_Error method?

Examples i've seen from Microsoft did not elude to having to do that.

-Demetri


"Juan T. Llibre" wrote:

> re:
> > Why the heck doesn't it direct to my Error.aspx page and show the error that way?

>
> Any unhandled exception is captured by Application_Error.
>
> What does your Application_Error sub/void in global.asax have ?
>
> You should have something like :
>
> Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
> Server.Transfer("Error.aspx")
> End Sub
>
>
>
> Juan T. Llibre, asp.net MVP
> aspnetfaq.com : http://www.aspnetfaq.com/
> asp.net faq : http://asp.net.do/faq/
> foros de asp.net, en español : http://asp.net.do/foros/
> ===================================
> "Demetri" <(E-Mail Removed)> wrote in message
> news:A92CA73C-2AD6-4A65-A5B7-(E-Mail Removed)...
> >I posted this question about a week or so ago. I never got any replies so
> > please forgive me if you have already read this question.
> >
> > I have the following in my web config file:
> >
> > <customErrors mode="RemoteOnly" defaultRedirect="Error.aspx" />
> >
> > Here is the code in the Error.aspx:
> >
> > protected void Page_Load(object sender, EventArgs e)
> > {
> > Exception err = Server.GetLastError().GetBaseException();
> >
> > this.lblMessage.Text = err.ToString();
> > }
> >
> > If mode is set to RemoteOnly I still get the yellow screen of death.
> > If mode is set to Off I still get the yellow screen of death.
> > If mode is set to On I get the yellow screen of death that tells me to set
> > the mode to RemoteOnly or Off to see the actual error message.
> >
> > Why the heck doesn't it direct to my Error.aspx page and show the error that
> > way?
> >
> >
> > --
> > -Demetri

>
>
>

 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      23rd Aug 2006
re:
> what is the point in this if I still need to write code to
> do it in the Application_Error method?
> Examples i've seen from Microsoft did not elude to having to do that.


Hi, Demetri.

No offense, but you need to get your hands dirty with exception handling.
There's a lot more to this than you think there is.

There's plain Exceptions and there's Unhandled Exceptions.
They're handled via different methods.

Check out Peter Bromberg's excellent article on Unhandled Exceptions :
http://www.eggheadcafe.com/articles/20060305.asp

Also, check out this KB :
http://support.microsoft.com/?id=911816

....and, for good measure, see this Code Project article :
http://www.codeproject.com/aspnet/AS...onHandling.asp




Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Demetri" <(E-Mail Removed)> wrote in message
news:2281834A-C022-4818-8B31-(E-Mail Removed)...
> The Application_Error sub/void in global.asax has nothing. I didn't think it
> needed any code since the customErrors section has an attribute for the
> defaultRedirect, what is the point in this if I still need to write code to
> do it in the Application_Error method?
>
> Examples i've seen from Microsoft did not elude to having to do that.
>
> -Demetri
>
>
> "Juan T. Llibre" wrote:
>
>> re:
>> > Why the heck doesn't it direct to my Error.aspx page and show the error that way?

>>
>> Any unhandled exception is captured by Application_Error.
>>
>> What does your Application_Error sub/void in global.asax have ?
>>
>> You should have something like :
>>
>> Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
>> Server.Transfer("Error.aspx")
>> End Sub
>>
>>
>>
>> Juan T. Llibre, asp.net MVP
>> aspnetfaq.com : http://www.aspnetfaq.com/
>> asp.net faq : http://asp.net.do/faq/
>> foros de asp.net, en español : http://asp.net.do/foros/
>> ===================================
>> "Demetri" <(E-Mail Removed)> wrote in message
>> news:A92CA73C-2AD6-4A65-A5B7-(E-Mail Removed)...
>> >I posted this question about a week or so ago. I never got any replies so
>> > please forgive me if you have already read this question.
>> >
>> > I have the following in my web config file:
>> >
>> > <customErrors mode="RemoteOnly" defaultRedirect="Error.aspx" />
>> >
>> > Here is the code in the Error.aspx:
>> >
>> > protected void Page_Load(object sender, EventArgs e)
>> > {
>> > Exception err = Server.GetLastError().GetBaseException();
>> >
>> > this.lblMessage.Text = err.ToString();
>> > }
>> >
>> > If mode is set to RemoteOnly I still get the yellow screen of death.
>> > If mode is set to Off I still get the yellow screen of death.
>> > If mode is set to On I get the yellow screen of death that tells me to set
>> > the mode to RemoteOnly or Off to see the actual error message.
>> >
>> > Why the heck doesn't it direct to my Error.aspx page and show the error that
>> > way?
>> >
>> >
>> > --
>> > -Demetri

>>
>>
>>



 
Reply With Quote
 
Kevin Jones
Guest
Posts: n/a
 
      24th Aug 2006
Demetri,

the problem is that the error page is displayed by using re-direction,
that means that when you get into the page handler for the error page
the exception has disappeared. Calling

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

itself raises a null reference exception, because Server.GetLastError()
returns null (put a breakpoint here and see for yourself).

The way to handle this (as somebody mentioned) is to add an
Application_Error handler and in there either: Server.Transfer to
Error.aspx; or save the exception in the session and then in error.aspx
retrieve the exception from the session.

HTH

Kevin Jones

Demetri wrote:
> I posted this question about a week or so ago. I never got any replies so
> please forgive me if you have already read this question.
>
> I have the following in my web config file:
>
> <customErrors mode="RemoteOnly" defaultRedirect="Error.aspx" />
>
> Here is the code in the Error.aspx:
>
> protected void Page_Load(object sender, EventArgs e)
> {
> Exception err = Server.GetLastError().GetBaseException();
>
> this.lblMessage.Text = err.ToString();
> }
>
> If mode is set to RemoteOnly I still get the yellow screen of death.
> If mode is set to Off I still get the yellow screen of death.
> If mode is set to On I get the yellow screen of death that tells me to set
> the mode to RemoteOnly or Off to see the actual error message.
>
> Why the heck doesn't it direct to my Error.aspx page and show the error that
> way?
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Errors =?Utf-8?B?bWFuaWthMDI=?= Microsoft Dot NET 0 25th Oct 2006 10:08 PM
Custom Icon for custom form not working =?Utf-8?B?YmFjazJncmlk?= Microsoft Outlook Form Programming 0 25th Aug 2005 01:15 AM
custom errors =?Utf-8?B?U2liZXM=?= Microsoft Access 1 4th Aug 2005 11:53 PM
Custom Errors Shapper Microsoft ASP .NET 1 19th Jul 2005 09:05 PM
Custom Errors in .NET C Microsoft Dot NET 0 13th Oct 2003 05:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:00 AM.