Asked by:
Difference between Custom Errors and Http Errors?

Question
-
User-1078128378 posted
Hi All,
i searched in google but i did not find the proper answer.
what is the difference between custom errors and httperrors?
and which one is used for application development
Thanks,
Monday, May 7, 2018 1:51 PM
All replies
-
User-369506445 posted
hi
Both are used to define error handling for a website, but different software refers to different config elements.
customErrors : This section was in use before IIS 7 introduced, IIS 6 5 and before fully use this section for handling custom http errors according to http status code.
httpErrors : IIS 7 and later use this section as well as customErrors section to handle custom http errors based on their file extensions if requested page extension register with ISAPI dll (.aspx, ashx, .asmx, .svc etc) like index.aspx then IIS pick up setting from customeErrors section else it pick up setting from httpErrors (IIS 7 hosted mode must be set as integrated mood not classic)
customErrors
are a legacy (backwards compatable) element, used by Visual Studio Development Server (aka. VSDS or Cassini).httpErrors
are the new element which is only used by IIS7.This highlights the possible problem when developing ASP.NET websites while using VSDS instead of the local IIS.
also please refer to below link
http://www.dotnetbull.com/2013/08/httperrors-vs-customerrors-webconfig-iis-aspnet.html
Monday, May 7, 2018 2:01 PM -
User-1078128378 posted
Hi Vahid,
Thanks for the reply.
can we use both custom errors and httperros in application?
if we use both, for example if we requested an 404 resource then which section(custom errors,http errors) will be executed?
Tuesday, May 8, 2018 5:35 AM -
User-369506445 posted
it depended on your iis version
if your iis version is less than 7 ,will be executed customErrors
but the httpErrors , IIS 7 and later use this section as well as customErrors section to handle custom http errors based on their file extensions if requested page extension register with ISAPI dll (.aspx, ashx, .asmx, .svc etc) like index.aspx then IIS pick up setting from customeErrors section else it pick up setting from httpErrors (IIS 7 hosted mode must be set as integrated mood not classic)
Conclusion , in iis and later if you use asp.net dll ,first looking for custom error ,otherwise http errors
Tuesday, May 8, 2018 5:55 AM -
User-1078128378 posted
HI Vahid,
I created sample application by configuring Http Errors and hosted in my local IIS(IIS 10.0)
and i placed error pages in Pages folder
now when I hit below url in browser (Default1.aspx not existed in my project)
http://localhost/CustomErrors/Default1.aspx
then it is properly redirecting to below 404 page.
http://localhost/CustomErrors/Pages/404.aspx
if 404 resource request came from root folder then it is redirecting properly and if 404 request came from sub folders then it is not properly redirecting.
consider i have Test1 folder in my solution when i entered below url(Test111.aspx not exists in my solution)
http://localhost/customerrors/Test1/Test111.aspx
then instead of recirecting 404 url it throws below error
could you please tell me where i am doing wrong?
Thanks,
Tuesday, May 8, 2018 10:15 AM -
User409696431 posted
Change your path to be from the root, not the current directory. "Pages/404.aspx" should be "/Pages/404.aspx", and the same change made for the 500.aspx page.
Tuesday, May 8, 2018 12:17 PM -
User-1078128378 posted
Hi kathy,
I changed Path as you suggested
<system.webServer> <httpErrors errorMode="Custom" existingResponse="Replace" > <clear/> <error statusCode="404" path="/Pages/404.aspx" responseMode="Redirect"/> <error statusCode="500" path="/Pages/500.aspx" responseMode="Redirect"/> </httpErrors> </system.webServer>
when i requested 404 resource
http://localhost/CustomErrors/Default1.aspx (default1.aspx not exists)
then it is redirecting to below page and gets below error
http://localhost/Pages/404.aspx
i am getting below error
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Pages/404.aspx
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2633.0
Tuesday, May 8, 2018 12:38 PM -
User409696431 posted
The obvious question is: Does http://localhost/Pages/404.aspx exist? Did you create that page? The error would suggest that you did not. Custom error pages are pages you create yourself to provide a friendlier/prettier and more useful (a link to the home page, for example) error page to your users.
Looking at your earlier post, you have your files under localhost/CustomErrors, but CustomErrors is not itself configured as an application root. The path to "/" goes to the application root. Fix one: either configure CustomErrors to be an application root, or fix the path to the error files to be "/CustomRoot/Pages/404.aspx", etc..
Tuesday, May 8, 2018 2:45 PM -
User-369506445 posted
please try below config:
<system.webServer> <httpErrors errorMode="Custom" > <remove statusCode="404" subStatusCode="-1" /> <remove statusCode="500" subStatusCode="-1" /> <error statusCode="404" path="Pages/404.aspx" responseMode="Redirect" /> <error statusCode="500" path="Pages/500.aspx" responseMode="Redirect" /> </httpErrors> </system.webServer> </configuration>
Wednesday, May 9, 2018 10:28 AM -
User-1078128378 posted
Hi Vahid,
I changed as you suggested.
if i requested an unexisted page from root folder like below then it is working.
http://localhost/CustomErrors/Default1.aspx
if i requested from subfolder like below
http://localhost/customerrors/Test1/Test111.aspx
then it is showing below error
<div class="content-container">
HTTP Error 404.20 - Not Found
No default document.
</div> <div class="content-container">
<fieldset>Most likely causes:
- A default document is not configured for the site.
- The URL contains a typographical error.
- Directory browsing is not enabled.
</div> <div class="content-container">
<fieldset>Things you can try:
- Configure a default document for this site. This is commonly default.aspx for ASP.NET and index.php for PHP.
- Review the browser URL.
- Enable directory browsing to allow listing the contents of the directory.
</div> <div class="content-container">
<fieldset>Detailed Error Information:
<div id="details-left">Module IIS Web Core Notification BeginRequest Handler Not yet determined Error Code 0x00000000 Requested URL http://localhost:80/customrrors/Test1/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Pages/Error404.aspx Physical Path C:\inetpub\wwwroot\customrrors\Test1\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Pages\Error404.aspx Logon Method Not yet determined Logon User Not yet determined </div> <div class="content-container">
<fieldset>More Information:
A default document is not configured for the site. </fieldset></div>
Monday, May 14, 2018 6:43 AM -
User-369506445 posted
hi
I think your problem is about your error page path
for test please try below code and when you get 404 error ,your are navigate to google website
if it was correct with all of urls, then we know about where your problem is
<httpErrors errorMode="Custom" existingResponse="Replace"> <remove statusCode="404"/> <remove statusCode="500" subStatusCode="-1" /> <error statusCode="404" path="http://www.google.fr" responseMode="Redirect"/> <error statusCode="500" path="http://www.google.com" responseMode="Redirect" /> </httpErrors>
Monday, May 14, 2018 7:43 AM -
User-369506445 posted
please try below code
<httpErrors errorMode="Custom" existingResponse="Replace"> <remove statusCode="404"/> <error statusCode="404" path="/Pages/404.aspx" responseMode="Redirect"/> </httpErrors>
the above code navigate to 404 page from Anywhere
Monday, May 14, 2018 7:46 AM -
User-1078128378 posted
Hi Vahid,
I tried this code
<httpErrors errorMode="Custom" existingResponse="Replace"> <remove statusCode="404"/> <remove statusCode="500" subStatusCode="-1" /> <error statusCode="404" path="http://www.google.fr" responseMode="Redirect"/> <error statusCode="500" path="http://www.google.com" responseMode="Redirect" /> </httpErrors>
this is working properly.
if an 404 error exists it is navigating to google page
but in my project i cant able to give full path( i can able to give only absolute path)
Monday, May 14, 2018 11:20 AM -
User-1078128378 posted
I Tried this code
<httpErrors errorMode="Custom" existingResponse="Replace"> <remove statusCode="404"/> <error statusCode="404" path="/Pages/404.aspx" responseMode="Redirect"/> </httpErrors>
but it is also not working
from root or sub folder if i request any unknown resource (http://localhost/CustomErrors/Test1.aspx( My requested url))it is navigating to
http://localhost/Pages/404.aspx
it is searching out side of the root folder(here my root folder is CustomErrors)
Monday, May 14, 2018 11:26 AM -
User409696431 posted
When the path starts with "/" , that means start at the root of your site. That means http://localhost/Pages/404.aspx. CustomErrors is not the root of your site. If it were, that folder name wouldn't show in the browser. See my earlier post about this.
What server are you using to test the site?
Monday, May 14, 2018 4:59 PM -
User-1078128378 posted
Hi Kathy,
but in iis i created application name as customErrors
so my site root would be CustomErrors
Tuesday, May 15, 2018 5:54 AM -
User-369506445 posted
hi
i tried below config on iis 7.5 and 8 and it was correct
<?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET application, please visit https://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <system.web> <compilation debug="true" targetFramework="4.5.2"/> <httpRuntime targetFramework="4.5.2"/> <!-- other settings --> </system.web> <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/> <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/> </compilers> </system.codedom> <system.webServer> <httpErrors errorMode="Custom" existingResponse="Replace"> <remove statusCode="404"/> <error statusCode="404" path="/Pages/404.aspx" responseMode="Redirect"/> </httpErrors> </system.webServer> </configuration>
and when i insert a wrong url , i navigate to 404 page
for 402 Error
404.20 occurs if a default document is not found. Go to WebMatrix 'Settings' section and add new default document, say default.cshtml (and make sure that default.cshtml is present in the site home directory) and try to run the site again.
also if you local-host have a port for example
http://localhost:8010/default.aspx
it's different with
http://localhost/default.aspx
Tuesday, May 15, 2018 6:29 AM -
User409696431 posted
If your site root is CustomErrors, the link to it would not be http://localhost/CustomErrors. It would be just http://localhost:nn (where nn is a port number that you mapped to it in Bindings). The application name or site name is not a name that shows after localhost. Check your site bindings in IIS manager, pick a port number, and use that to preview your site.
Tuesday, May 15, 2018 1:32 PM