404 does not append aspxerrorpath for non aspx pages - iis-7.5

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

Related

how to implement {REQUEST_FILENAME} in web.config - httpErrors

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>

Trying to create a custom error page with IIS (server is using php)

So the title says it. I just cannot get the web.config file working. If anyone knows what I'm doing wrong here it would be nice. http_error_handler.php takes a get request in the url and displays the error according to that.
Contents of web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<remove value="index.php" />
<add value="index.php" />
</files>
</defaultDocument>
<httpErrors>
<clear />
<remove statusCode="403" subStatusCode="-1"></remove>
<remove statusCode="404" subStatusCode="-1"></remove>
<remove statusCode="405" subStatusCode="-1"></remove>
<remove statusCode="408" subStatusCode="-1"></remove>
<remove statusCode="500" subStatusCode="-1"></remove>
<remove statusCode="502" subStatusCode="-1"></remove>
<remove statusCode="504" subStatusCode="-1"></remove>
<error statusCode="403" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
<error statusCode="404" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
<error statusCode="405" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
<error statusCode="408" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
<error statusCode="500" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
<error statusCode="502" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
<error statusCode="504" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode="On">
<error statusCode="403" redirect="/php/handlers/http_error_handler.php?status=403"></error>
<error statusCode="404" redirect="/php/handlers/http_error_handler.php?status=404"></error>
<error statusCode="405" redirect="/php/handlers/http_error_handler.php?status=405"></error>
<error statusCode="408" redirect="/php/handlers/http_error_handler.php?status=408"></error>
<error statusCode="500" redirect="/php/handlers/http_error_handler.php?status=500"></error>
<error statusCode="502" redirect="/php/handlers/http_error_handler.php?status=502"></error>
<error statusCode="504" redirect="/php/handlers/http_error_handler.php?status=504"></error>
</customErrors>
</system.web>
</configuration>
replace
<httpErrors>
with
<httpErrors errorMode="Custom">

Custom 404 error page not working on IIS 8.5

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!

Configuring web.config for Azure Web Sites

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>

System.webServer and System.web sections of web.config

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.

Resources