DefaultRedirect wont work for aspx pages

G

Gary

I have the following in my web.config....

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

but, my error page does not display. Instead a 'Runtime Error' page
displays showing how to setup CustomErrors.

However, if I make my error page a .htm page it shows fine.

Anyone know why?
thanks,
G
 
S

Steven Cheng[MSFT]

Hi Richard,


Thanks for posting in the community! My name is Steven, and I'll be
assisting you on this issue.
From your description, you've generated an custom error page(an aspx page)
to provide a friendly error display UI when some unhandlered exceptions
occur. However you found the "defaultRedirect" custom error page you set
in the web.config file didn't work, you still got a runtime error instead
of the correct error page, yes?
If there is anything I misunderstood, please feel free to let me know.


First , I'd like to ask for some further infos on this issue:
1. Do you visit the certain page from a remote client or local client.
Since the "RemoteOnly" option will redirect only remote user to the custom
error page. Also, I may try set it as "On" to see whether it works.

2. Check on your custom error page( the aspx page) to see whether it is
correct at all? Also, you may try using a very simple aspx page to test
whether the problem is on the error page.

3. Do you have any other particular configuration setting for the certain
web application, such as formAthentication for page protection(folder
protection). As for this point, you can try creating a new simple web
application and try using a custom error page to see whether the problem
remains.

Please check out the above steps and it would quite helpful if you could
provide me some more infos so as for me to repro the problem on my side.
Thanks.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Gary

Steven,
Thanks for your reply. (BTW my name is Gary, not Richard :)

I have narrowed it down. It will work on an aspx page that has no code in
the codeBehind vb file. But, if I put..

If Not IsPostBack Then
lblMessage.Text = Server.GetLastError.Message
End If

in the Page_Load event then it does not work. The reason I wanted to use an
aspx page in the first place was because I wanted to at least inform the
user of the message so that they could report the problem. Using just an
..htm page robs the user of all information. Is there anyway to get it to
work with some code in the page? Why does it not work with code in the
page?
Thanks,
Gary
 
S

Steven Cheng[MSFT]

Hi Gary,


Thanks for your response. Regarding on this issue, I've done some further
research and the problem may due to the
"GetLastError()" method you used in the custom error page. Here is the
description in the KB article:
---------------
<customErrors
defaultRedirect="http://hostName/applicationName/errorStatus.htm" mode="On">
<error statusCode="404" redirect="filenotfound.htm" />
</customErrors>

Note The page that is specified in defaultRedirect of the <customErrors>
section is an .htm file. If you intend to use GetLastError in an .aspx page
(which the Page_Error and Application_Error samples do), you must store the
exception in a session variable or some other approach before the redirect
takes place.

# the complete artile is accessable at the following url:
#HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using Visual C#
.NET
http://support.microsoft.com/?id=306355

#HOW TO: Create Custom Error Reporting Pages in ASP.NET Using Visual Basic
.NET
http://support.microsoft.com/?id=308132
---------------

So I suggest that you try remove the "Server.GetLastError" statement in
the custom error aspx page to see whether the problem will go away. Also,
you may try the KB's suggestion that stored the GetLastError's return value
in the Session(in Page_Error or Application_Error event) before redirect
to the custom error aspx page, then retireve it from the Session in the
custom error page for later use.

In addition, I've searched some other references an infos on using custom
error page, you may also have a look to see whether they're helpful:
#BUG: DefaultRedirect Does Not Work When You Use SmartNavigation
http://support.microsoft.com/?id=813831

#Handling Errors(ASP.NET QuickStart)
http://samples.gotdotnet.com/quickstart/aspplus/doc/handlingerrs.aspx#custom


If you feel anything unclear or need any further assistance, please feel
free to post here.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi Gary,


Have you had a chance to try my suggestion or have you resolved the
problem? If you need any assistance, please feel
free to let me know.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Gary

Steven
It seems you did not read the message you replied to. It said....

"I have narrowed it down. It will work on an aspx page that has no code in
the codeBehind vb file. But, if I put..

If Not IsPostBack Then
lblMessage.Text = Server.GetLastError.Message
End If

in the Page_Load event then it does not work. The reason I wanted to use an
aspx page in the first place was because I wanted to at least inform the
user of the message so that they could report the problem. Using just an
..htm page robs the user of all information. Is there anyway to get it to
work with some code in the page? Why does it not work with code in the
page?"


As you can see, this remains a problem.
Gary
 
S

Steven Cheng[MSFT]

Hi Gary,


Thanks for your followup. As for the problem in this issue, I've found that
you'd opened another new thread in this queue which also discussing on this
problem. I've replied you in that thread. Do you think it convenient if we
continue to discuss this problem in the new thread? If so, please feel
free to followup in the new thread if you have any questions or need any
help. Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top