Asked by:
Custom errors in web.config

Question
-
User694418659 posted
Hi,
Trying unsuccessfully to redirect users to custom error pages from my web.config file. I see the default browser error page on errors.
Here's the code I'm using:
<system.web> <customErrors mode="RemoteOnly" defaultRedirect="error.aspx"> <error statusCode="404" redirect="notfound.aspx" /> <error statusCode="403.6" redirect="restricted.aspx" /> </customErrors> </system.web>
Any ideas what's wrong?
Thanks,
MartFriday, June 14, 2019 10:05 AM
All replies
-
User753101303 posted
It should work from a remote machine and for requests that are handled by ASP.NET rather than just by IIS. That is make sure you are not using a browser on the same machine than the web server and that you are testing for now using z.aspx rather than z.htm.
Friday, June 14, 2019 11:50 AM -
User-1174608757 posted
Hi stabes,
According to your code, it seems no problems.However,I notice that you directly write code as below:
defaultRedirect="error.aspx"
"error.aspx" is the relative path of error page which means that page you want to redirect should be directly in the webapplication but not in any folder of application.
For instance if the error page is in the folder as below:
Then you should write code as below:
<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPages/Oops.aspx"> <error statusCode="404" redirect="~/ErrorPages/404.aspx" /> </customErrors>
Best Regards
Wei
Monday, June 17, 2019 2:08 AM -
User694418659 posted
See updated code attached. No luck. Whatever I've tried, it doesn't work.
<system.web> <customErrors mode="RemoteOnly" defaultRedirect="~/errors/error.aspx"> <error statusCode="404" redirect="~/errors/notfound.aspx" /> <error statusCode="403.6" redirect="~/errors/restricted.aspx" /> </customErrors> </system.web>
Monday, June 17, 2019 4:03 PM -
User-1174608757 posted
Hi stabes,
Are you testing on your local machine?If so,I suggest that you could change customErrors mode to 'On' which you could see as below:
<system.web> <customErrors mode="On" defaultRedirect="about.aspx"> <error statusCode="404" redirect="about.aspx" /> </customErrors>
Then make sure the page you are testing ends with aspx.I think it will show your customer page.
Best Regards
Wei
Tuesday, June 18, 2019 1:58 AM