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!
Related
I am looking to implement a querystring of my error page, the page originally requested. but unfortunately I do not find how.
Thank you for your help
<?xml version="1.0"?>
<configuration>
<system.webServer>
<httpErrors>
<remove statusCode="401" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="401" path="/error.aspx?type=401&page={REQUEST_FILENAME}" responseMode="Redirect" />
<error statusCode="403" path="/error.aspx?type=403&page={REQUEST_FILENAME}" responseMode="Redirect" />
<error statusCode="404" path="/error.aspx?type=404&page={REQUEST_FILENAME}" responseMode="Redirect" />
<error statusCode="500" path="/error.aspx?type=500&page={REQUEST_FILENAME}" responseMode="Redirect" />
</httpErrors>
</system.webServer>
</configuration>
I have a simple question:
Is possible to send the Response.Status = "404 Not Found" from a .asp page, but continue to render the actual page?
Seems that when i send Response.Status = "404 Not Found" IIS moves to the default 404 error page, while i would like to continue to render my page. This is a case of a CMS where for some reason someone can type a unexistent permalink and want to display a "OPS not found content page" instead to redirect to a custom or default 404 asp page.
there is a specific web.config setup?
I've followed discussion here:
Configuring custom ASP 404 page with redirect for IIS7 website
And thought to use then option
<httpErrors existingResponse="PassThrough" />
But for some reason it gave me error 500.
The IIS version is 8.5 asp 3.0 / .NET 3.5
my actual web.config is:
<?xml version="1.0" encoding="UTF-8"?>
<httpErrors errorMode="DetailedLocalOnly"/>
<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true" />
<caching enabled="true">
<profiles>
<add extension=".gif" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".js" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".css" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".jpeg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
</profiles>
</caching>
<staticContent>
<remove fileExtension=".js" />
<mimeMap fileExtension=".js" mimeType="text/javascript" />
<remove fileExtension=".eot" />
<remove fileExtension=".ttf" />
<remove fileExtension=".otf"/>
<remove fileExtension=".woff"/>
<remove fileExtension=".woff2"/>
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<mimeMap fileExtension=".ttf" mimeType="font/ttf" />
<mimeMap fileExtension=".otf" mimeType="font/otf" />
<mimeMap fileExtension=".woff" mimeType="font/x-woff" />
<mimeMap fileExtension=".woff2" mimeType="font/x-woff2" />
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>
<rewrite>
<rules>
<rule name="Rewrite to friendly URL">
<match url="^site/([_0-9a-z-]+)" />
<action type="Rewrite" url="/default.asp?pl={R:1}" />
</rule>
</rules>
</rewrite>
Thank in advance for any solution :)
EDIT:
After many test i found the solution:
<httpErrors errorMode="DetailedLocalOnly" existingResponse="PassThrough"/>
The 500 error i get if i add the line separate from the "DetailedLocalOnly" is now solved using a one line with both param.
Maybe it is only a typo in your web.config. If above is your configuration file, you forgot to enter the system.webServer tag level.
I tested this on IIS 8.5 and it worked as expected. So the ASP generated
content was shown while the page returned a 404 status code. I really only used following configuration:
<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>
Alternatively, but not recommended, it also worked with following configuration:
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
For the interested, here is the link to the documentation.
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>
i am using ELMAH to log errors, it works fine for pages with aspx, i.e. eroordfs.aspx
but when it has a non aspx extension or no extension, my error page loads with no aspxerrorpath in the url, i think this is the reason that elmah is not logging the error.
i am using iis7.5
my web.config details are as follows:
<httpErrors errorMode="Custom">
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/404.aspx" responseMode="ExecuteURL" />
<error statusCode="500" subStatusCode="-1" prefixLanguageFilePath="" path="/500.aspx" responseMode="ExecuteURL" />
</httpErrors>
and
<customErrors mode="On">
<error statusCode="404" redirect="~/404.aspx" />
<error statusCode="500" redirect="~/500.aspx" />
</customErrors>
thanks in advance for any advice you can offer
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.