What is point to have two separate sections for defining error documents in web.config?
<system.webServer>
...
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/ErrorPage_404.aspx" responseMode="ExecuteURL" />
</httpErrors>
...
</system.webServer>
and
<system.web>
...
<customErrors defaultRedirect="/Forms/Errors/Error.aspx" mode="On">
<error statusCode="404" redirect="/ErrorPage_404.aspx" />
</customErrors>
...
</system.web>
If I remove first section, IIS7 will not show error pages. If I remove second one, my VS debugger will not show error pages.
I always thought that system.web applied to IIS6 and below, while system.webServer applied to IIS7+, but actually it seems that the real answer is that system.web is for .aspx / .asp pages through its handler mapping, and everything else goes through system.webServer.
Have a look at this webpage for a pretty clear explanation.
Related
I have a tiny website that serves as my maintenance placeholder page.
It has one html document that gets served as an error page for 404s and 403s which will, since there's nothing else there, be always served.
But really, I wish the response code was rather something like 503. How can I do that purely in web.config without resorting to ASP.NET?
Try this:
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="File" >
<remove statusCode="500" />
<error statusCode="500"
prefixLanguageFilePath="C:\Contoso\Content\errors"
path="500.htm" />
</httpErrors>
</system.webServer>
</configuration>
See this link for more info:
I have recently moved host and have had to set up Customer Errors again in IIS.
I can go to IIS Admin and Error Pages as follows:
Then I can go to the Custom Errors, and have set up the options as follows:
That creates my web.config file as follows:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="ExecuteURL">
<remove statusCode="500" subStatusCode="100" />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/error_404.asp" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/error_500.asp" responseMode="ExecuteURL" />
<error statusCode="500" subStatusCode="100" path="/error_500.asp" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
When I test the pages, the 505 error works fine, and redirects to the right page, but the 404 doesn't redirect and returns the standard IIS 404 error. I have confirmed that the 404 error page is in place on the server in the correct location.
I can't see what else I need to do.
Got it working in the end (helped by finding this: http://forums.iis.net/t/1173965.aspx), using:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
<remove statusCode="500" subStatusCode="100" />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/error_404.asp" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/error_500.asp" responseMode="ExecuteURL" />
<error statusCode="500" subStatusCode="100" path="/error_500.asp" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
I was having a similar problem where I have a custom 404 page at /Error/Missing but it wasn't showing up for static files that didn't exist or for folders/directories that DID exist (but shouldn't be served by MVC). The controller for Missing page has the following:
Response.AddHeader("Content-Type","text/html; charset=utf-8");
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = (int)HttpStatusCode.NotFound; // 404
Also I wasn't getting my custom error page if I returned the following in a controller:
return HttpNotFound();
I could change the IIS default errors to a blank page if I set PassThrough:
<httpErrors existingResponse="PassThrough" />
Changing it to "Replace" made the default IIS errors show again.
I also had a section in my web.config, but I've taken it out as I'm IIS 8.5 it doesn't look like it's needed any more.
<system.web>
<customErrors mode="Off">
</system.web>
So basically I couldn't get rid of default IIS messages - either one-liner or the more detailed ones. My httpErrors section looked like this:
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
<remove statusCode="404" />
<error statusCode="404" path="/Error/Missing" />
</httpErrors>
Finally I came across this question and I was looking at the other answer on this question and realised that I could try a ResponseMode on each error line. I thought that wouldn't be necessary as I had the defaultResponseMode set - but it makes a difference!!
So, if you want to serve up a custom 404 page use this httpErrors module:
<httpErrors errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="/Error/Missing" responseMode="ExecuteURL" />
</httpErrors>
I've put all these details here so this hopefully shows up for someone else searching the same things I did - hope it helps!
I have enabled customErrors in my MVC5 web application as below.
<customErrors defaultRedirect="/Error/InternalServerError" mode="On">
<error redirect="/Error/NotFound" statusCode="404" />
<error redirect="/Error/InternalServerError" statusCode="500" />
</customErrors>
I have Area defined called "Admin" and I need to turn off customErrors for that particular Area.
I have tried adding web.config file with following code inside Areas folder.
<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
</configuration>
But still my custom error is displaying, how can I disable customErrors only for a given Area in MVC5?
Wrap your customErrors in a location tag within your root web.config:
<location path="areaName">
<system.web>
<customErrors mode="Off" />
</system.web>
</location>
I'm new to Azure WebSites. Looking to personalise 400 series pages. From reading I understand in IIS this is configured using a web.config file.
While there is lots of great supporting documentation on how to configure this file, it doesn't actually tell me where the file is meant to be saved on an Azure hosted platform. I've tried D:\home\site\wwwroot\web.config but as soon as I put some basic configuration like:
<?xml version="1.0"?>
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="on"/>
<httpErrors>
<remove statusCode="401" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="401" path="http://foo.com/default.htm" responseMode="Redirect" />
<error statusCode="403" path="/errors/403.htm" responseMode="ExecuteURL" />
<error statusCode="404" path="/somedir/oops404.htm" responseMode="ExecuteURL" />
<error statusCode="500" path="/somedir/500.asp" responseMode="ExecuteURL" />
</httpErrors>
</system.web>
</configuration>
The site begins to return a 500 (503 to be precise).
I've tried restarting the instance using the Manage console but still have the same issue.
Any advice would be greatly appreciated, I'm trying to configure default error pages and CORS for the site.
<httpErrors> is a child element of <system.webServer> (not <system.web>) - see details at HTTP Errors in the IIS.net. Move <httpErrors> to <system.webServer>. For example...
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL" >
<remove statusCode="403"/>
<remove statusCode="404"/>
<remove statusCode="500"/>
<error statusCode="403" responseMode="ExecuteURL" path="/Error403" />
<error statusCode="404" responseMode="ExecuteURL" path="/Error404" />
<error statusCode="500" responseMode="ExecuteURL" path="/Error500" />
</httpErrors>
</system.webServer>
At witts end with this problem.
I am working on a busy site which we have migrated from IIS6 to IIS7, which uses a custom 404.asp handler to process SEO friendly URLS and return the correct content from included asp scripts.
We have managed to get the 404 method to work on IIS7, but if there is a error in the code somewhere, we have set iis to run 500.asp which is designed to log the error and returns a useful message to the user.
So the flow should be :
User types Friendly URL : e.g. http://www.sitename.com/testarticle/
Which does not exist and fires 404.asp
404 looks up "testarticle" in our database and returns the correct content.
That all works..
If error Should call 500.asp
- Logs Error in our Log (Works)
- Returns Msg to the screen (Not working - Just Get Blank Page)
This worked in IIS6, however in IIS7 the 500.asp logs the error in our log, but absolutely nothing is written out to the screen - We just get a blank screen. Very Frustrating.
We have tried changing what feels like every setting in IIS, and web.config but we can't get this to work.
Any help much appreciated..
Cheers
I did a similar migration a little while ago and this is the web.config settings I ended up with (well just the relevant parts):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/common/404.asp" responseMode="ExecuteURL" />
<remove statusCode="500" subStatusCode="100" />
<error statusCode="500" subStatusCode="100" prefixLanguageFilePath="" path="/common/500.asp" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
Note the web.config section used. When done using the customErrors element it did not work for me. This was the only way I could get both URL rewriting using a custom 404 error page and custom 500 errors working in Classic ASP. Hopefully that helps you.
So you get a blank page?
I had a similar problem, the solution is really weird but works for sure.
I'll be very pragmatic, do the following.
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL" existingResponse="Auto">
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" subStatusCode="100" prefixLanguageFilePath="" path="/500.100.asp" responseMode="ExecuteURL" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/404.asp" responseMode="ExecuteURL" />
</httpErrors>
The blank page will be "not blank" if you assure that it ends with:
Response.Flush()
When IIS executes the code inside /500.100.asp it doesn't flush the response and it ends with a blank page.
I assure that "404" and "500.100" custom errors can be possible in IIS7.5/IIS8 and Classic ASP ;)