Custom Error not working in actual website for 404 - asp.net

I am trying to setup custom error for my website which works fine on local-host mode="On".
But same fails on actual website.
Below is my code for web.config
<customErrors mode="RemoteOnly" defaultRedirect="~/error/Message.aspx?msg=The page you requested could not be found.">
<error statusCode="404" redirect="~/error/Default.aspx?PID=32"/>
<error statusCode="403" redirect="~/error/Forbidden.aspx"/>
<error statusCode="400" redirect="~/error/Error.aspx"/>
<error statusCode="500" redirect="~/error/InternalError.aspx"/>
</customErrors>
I am using IIS 7.5 on my local machine and same is being used on the web server.
Do i need to change any specific setting on Production server to make it work
Error message i am still getting on live website for 404
Not Found
The requested document was not found on this server.
Web Server at xyz.com

Final version with following code worked
...
<customErrors mode="RemoteOnly" defaultRedirect="~/error/Message.aspx?msg=The page you requested could not be found.">
<error statusCode="404" redirect="~/error/Default.aspx?PID=32"/>
<error statusCode="403" redirect="~/error/Forbidden.aspx"/>
<error statusCode="400" redirect="~/error/Error.aspx"/>
<error statusCode="500" redirect="~/error/InternalError.aspx"/>
</customErrors>
....
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/error/Default.aspx?PID=32" responseMode="ExecuteURL"/>
</httpErrors>
</system.webServer>

the web.config part seems to be ok, even if I would suggest static html for default error page redirection.
How do you test this issue on remote server?
By typing url xyz.com/xxxxxx where xxxxxx is page which not exist?
If yes, so is xxxxxx without file extension?
And does 404 redirect works if xxxxx ends with file extension which is one of website default page? e.g. xxxx.aspx
Try this post
asp.net custom error page and file without extension

Related

How To : Dnn Custom Error Pages

Default error pages may expose a lot of information, Like the language and the server you use, and such Info. could be used by malicious users to attack your site and your server.
Also default error pages look very ugly and outdated design, which may harm your brand.
So It's always recommended to use custom error pages..
So, How Could I display a custom error page in DNN when error occurs ?
1.To Disable DNN Error Handling, and Let Errors Bubble..
Host Settings >> Appearance >> Un-Check "Use Custom Error Messages? "
2.To Redirect Users To, Can be aspx page, but I prefer HTML
Then Create HTML Page at the root with Style
3.in Enable CustomErrors in Web.Config :
<customErrors mode="On">
<error statusCode="500" redirect="/MyCustomError.html"/>
<error statusCode="404" redirect="/MyCustomError.html"/>
<error statusCode="403" redirect="/MyCustomError.html"/>
</customErrors>
Also You can Override IIS Error Pages and Redirect to your Custom Error Pages using the below web.config snippet
<httpErrors>
<remove statusCode="404" subStatusCode="-1"/>
<error statusCode="404" prefixLanguageFilePath="" path="/MyCustomError.aspx" responseMode="ExecuteURL"/>
<remove statusCode="403" subStatusCode="-1"/>
<error statusCode="403" prefixLanguageFilePath="" path="/MyCustomError.html" responseMode="ExecuteURL"/>
</httpErrors>

Custom error in web.config not working for 404

I am trying to set up custom error for my website, which works fine on my local machine but it fails on the server. Below is my code.
<system.web>
<customErrors mode="On" defaultRedirect="~/Pages/Error.aspx">
<error statusCode="404" redirect="~/Pages/PageNotFound.aspx"/>
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="PassThrough"defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="~/Pages/PageNotFound.aspx" responseMode="ExecuteURL"/>
</httpErrors>
</system.webServer>
I am using IIS 8 on my local server and IIS 7 on the live server. Should I change this code in any way to make it work?
Also, when I try to access a page, eg: xyz.aspx, it does'nt show anything except for a white browser window.
Check if you have more then one web config Or Check your web config file is inside your project correctly.

I am using UrlRewritingNet.UrlRewrite dll, how to redirect to Error page when bad request get fired?

Currently I am using UrlRewritingNet.UrlRewrite dll for URL rewriting in Asp.Net #3.5.
Without using any special character it works fine ex. URL1.
But after giving special characters in URL it throws Bad Request error ex. URL2
URL1: http://www.example.com/search/0253
URL2: http://www.example.com/search/0253:0253
To handle this error, I want to redirect it to some other Error Page, How can I do this?
On IIS 7+ you can define error pages for all statuses, for 400 Bad Request :
<httpErrors>
<error statusCode="400" path="/bad-request.aspx" prefixLanguageFilePath="" responseMode="ExecuteURL"/>
</httpErrors>
or trough IIS console go to the error pages and add custom error page for status code 400 :
The best way is by using Web.config file like
<system.web>
<!-- other system.web stuff -->
<customErrors defaultRedirect="/Error404.aspx" mode="On" redirectMode="ResponseRewrite">
<error redirect="/Error404.aspx" statusCode="404" />
</customErrors>
</system.web>
<system.webServer>
<!-- other system.webServer stuff -->
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Error404.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
For more details click here

DNN Custom Error Page Issue

I am working on DNN 7.0. I create a ErrorPage.aspx and set it as defaultredirect and another page 404error.aspx and set it with the status code 404.
now if i access the website like
www.abc.com/testing.aspx , and testing.aspx donot exists, it takes me to 404error.aspx page
then i try to access my website by
www.abc.com/testing , now it is showing that ugly asp.net error.
need some assistance what am i doing wrong, or what i am missing.
Thanks
Got it working.
In web.config implemented httpErrors and CustomErros tag
like
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/404Error.aspx" responseMode="ExecuteURL" />
</httpErrors>
and
<customErrors mode="On" defaultRedirect="/CustomErrorPage.aspx">
</customErrors>

Why are custom error pages not working for 404 errors

I have set up a page to handle errors that occur in a website I work on using web.config. I have used the customErrors section in web.config to do this, as described here
Here is the relevant section
<customErrors mode="On" defaultRedirect="page.aspx?IDDataTreeMenu=357">
<error statusCode="403" redirect="page.aspx?IDDataTreeMenu=357"/>
<error statusCode="404" redirect="page.aspx?IDDataTreeMenu=357" />
</customErrors>
This seems to work for all errors except 404. I just get the standard IIS 404 error when accessing a URL that doesn't exist.
What am I missing here?
This site is hosted on a shared server, so changing settings in IIS is not an option
Check with the ISP and see if they have a place where you can insert a reference to your own custom 404 page.
At Network Solutions they give you a control panel and a page where you can set this up.
<httpErrors>
<clear />
<error statusCode="404" subStatusCode="-1" path="/404.asp" responseMode="ExecuteURL" />
</httpErrors>

Resources