Answered by:
How to redirect to custom error page for 404.7 errors

Question
-
User-1188570427 posted
I want to redirect my website to a generic error page IF they try to get to my .txt files.
I get this error now:
HTTP Error 404.7 - Not Found
The request filtering module is configured to deny the file extension.
but I want to go to my generic error page instead of the 404.7 error.
I have this in my custom errors page, but locally it doesn't work:
<customErrors mode="On" defaultRedirect="Error.html"> <error statusCode="404" redirect="Error.html" /> </customErrors>
Sunday, January 20, 2019 4:40 AM
Answers
-
User409696431 posted
Try adding
<system.webServer> <httpErrors errorMode="Custom"> <remove statusCode="404"/> <error statusCode="404" path="/Error.html" /> </httpErrors> </system.webServer>
customErrors handles pages processed by asp.net. httpErrors can handle static files and other extensions not handled by asp.net.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, January 20, 2019 6:29 AM
All replies
-
User409696431 posted
Try adding
<system.webServer> <httpErrors errorMode="Custom"> <remove statusCode="404"/> <error statusCode="404" path="/Error.html" /> </httpErrors> </system.webServer>
customErrors handles pages processed by asp.net. httpErrors can handle static files and other extensions not handled by asp.net.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, January 20, 2019 6:29 AM -
User283571144 posted
Hi tvb2727,
As far as I know, the 404.7 means the request filtering is actually filtering for a blank file name. Therefore you have to add this to the request filtering block in the web.config:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <security> <requestFiltering> <fileExtensions allowUnlisted="true" > <remove fileExtension=".txt" /> <add fileExtension=".txt" allowed="true"/> </fileExtensions> </requestFiltering> </security> </system.webServer> </configuration>
Then it will pass the IIS and use your own custom page.
Best Regards,
Brando
Monday, January 21, 2019 5:44 AM -
User-1188570427 posted
Try adding
<system.webServer> <httpErrors errorMode="Custom"> <remove statusCode="404"/> <error statusCode="404" path="/Error.html" /> </httpErrors> </system.webServer>
customErrors handles pages processed by asp.net. httpErrors can handle static files and other extensions not handled by asp.net.
This worked KathyW
Thank you!
Saturday, January 26, 2019 4:23 PM