Click here to Skip to main content
15,916,949 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I write in URl www.abc.com/wer.aspx (Wrong Page) then show my error page else i put www.abc.com/wer (wrong page without extension) then my error page not show.
Please help me in proper way.
I DO LIKE THIS ...in Web Config

XML
<customErrors mode="RemoteOnly" defaultRedirect="error.htm">
   <error statusCode="401" redirect="error.htm" />
   <error statusCode="402" redirect="error.htm" />
   <error statusCode="403" redirect="error.htm" />
   <error statusCode="404" redirect="error.htm" />
 </customErrors>
Posted
Updated 8-Jul-15 16:49pm
v2

If you want to see the error page when you run the project from Visual Studio, you have to set the mode to ON.

<customErrors mode="On" defaultRedirect="error.htm">


When you set mode to RemoteOnly, it renders error pages to external users alone.

Refer this MSDN article for more details:

https://msdn.microsoft.com/en-us/library/bb397417(v=vs.140).aspx[^]
 
Share this answer
 
ASP.NET handlers are not called for non-asp.net files.you can force the asp.net handler to operate on all requests by setting runAllManagedModulesForAllRequests as true in your web config as below
HTML
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
</system.webServer>


check : 404 Redirecting for non aspx pages[^]
 
Share this answer
 
Hope this Helps you out.

C#
<customerrors mode="RemoteOnly" defaultredirect="~/error.htm" redirectmode="ResponseRewrite" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900