I have an ASP.Net website and I want to use a custom error page. I put the following code in my web.config
<customErrors mode="On" defaultRedirect="~/error.aspx"> <error statusCode="404" redirect="~/error.aspx" /> </customErrors>
The problem is when i go to a URL that does not exist is still uses the 404 error page specified in IIS Manager.
Question: How can I make it use the error.aspx page I have created? Why do the settings in IIS Manager override the web.config?
In ASP.Net, error can be handled programmatically by writing appropriate code in the page-level error event, for errors on an individual page or in the application-level error event for handling errors that may occur in any page of the application.
Try this way, almost same.. but that's what I did, and working.
<configuration> <system.web> <customErrors mode="On" defaultRedirect="apperror.aspx"> <error statusCode="404" redirect="404.aspx" /> <error statusCode="500" redirect="500.aspx" /> </customErrors> </system.web> </configuration>
or try to change the 404 error page from IIS settings, if required urgently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With