Thanks in advance for replying.
Simple Azure ASP.net 4.5 web forms website.
I am handling custom errors in the Global.asax. Page missing works when the middle of the url is changed. However, if the end is changed. It says 404 error and when deployed to Azure, it states a single line "Resource missing"
I am thinking this is web server issue and if my huntch is correct, how do I
a) Fix this on the IIS express in VS 2013
b) Fix this when deployed to Azure Websites
Cheers, Thnx & All the best
KFC
First of all, I'm kind of shooting in the dark here. Could you possibly post the httpErrors and customErrors nodes from your Web.config, and the error handling code you're using in Global.asax?
That said, Global.asax isn't a great place to be handling custom error pages. You can use the httpErrors node in your Web.config to have IIS (7+, Azure is fine) catch errors and redirect. This lets you catch errors from inside (e.g. application exceptions) and outside (e.g. request validation failures, missing static files) your application:-
<httpErrors errorMode="Custom" existingResponse="Replace">
<clear />
<error statusCode="400" responseMode="ExecuteURL" path="/Error" />
<error statusCode="403" responseMode="ExecuteURL" path="/Error/Forbidden" />
<error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" />
<error statusCode="500" responseMode="ExecuteURL" path="/Error" />
</httpErrors>
Remove the customErrors node entirely. It is unnecessary.
I've put a full working example of using httpErrors for custom error pages up on github. You can also see it live on azure web sites.
Related
The Condition
I have created my own web framework, which intercepts Error 404 and displays the appropriate content depending on the URL (it also sends the correct HTTP code 200 or 404 when the URL is valid or not). I have the entire framework under single /Default.asp (which includes several files, but that's not important here). It works perfect under IIS6, but I'm unable to figure out how to handle debugging and development under IIS7.
The Problem
The challenge is picking the correct Error Mode for the web.config file.
If I set errorMode=Custom then my code works and I can even see errors in my code while developing, but I can't debug other ASP files, because any error there, would be redirected to the /default.asp instead of showing it to me in the browser.
So, when I need to debug other ASP files, I would change the error mode from Custom to errorMode=Detailed
Then I can easily see the line number and the error description, but that means obviously that my framework would not be able to handle Errors 404 for non-existing URL's.
I have been doing this "dance" switching web.config every time I need to check something and it's getting very annoying. Here's my web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<!-- I'm changing Custom to Detailed here when I need to debug -->
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath=""
path="/Default.asp" responseMode="ExecuteURL" />
<!-- I have experimented with this, but unsuccessfully, so I comment it out
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" prefixLanguageFilePath=""
path="/Default.asp" responseMode="ExecuteURL" />
-->
</httpErrors>
<directoryBrowse enabled="false" />
</system.webServer>
</configuration>
Question:
Is it possible to use both methods simultaneously?
A custom .ASP file to process 404 (and possibly other errors) but also leaving the 500 errors to be processed by the server and display the detailed error.
All I need to see is the line number and the error description.
I have been doing some research and some thought into this for awhile, and can't seem to find a quality solution.
When we update our web software, we have to kill the application pool associated with the site. Not a big deal right?
Except customers are complaining they don't know why they see a 503 error and submit unnecessary tickets.
Things I know:
There is no way to customize the 503 page
This is normal when the application pool is down
We can't leave the application pool on while updating
Is it possible to have the site redirect to another site or different application pool on failure?
If it is I can create a "maintenance" page site and just have it redirect on error.
Until I know you can configure error pages from IIS Manager. Under the section .NET Error Pages.
By the way I think your solution should be posible using URL Rewriter.
Here #ruslany shows an example about how to do any request of a site returns a 503.
and here you can read about error pages customization using that module
also here a very good documentation about.
And to provide a bit of code. You are supposed to replace error pages like this:
<httpErrors>
<error statusCode="401" prefixLanguageFilePath="c:\inetpub\custerr" path="401.htm" />
<error statusCode="403" prefixLanguageFilePath="c:\inetpub\custerr" path="403.htm" />
<error statusCode="404" prefixLanguageFilePath="c:\inetpub\custerr" path="404.htm" />
<error statusCode="405" prefixLanguageFilePath="c:\inetpub\custerr" path="405.htm" />
<error statusCode="406" prefixLanguageFilePath="c:\inetpub\custerr" path="406.htm" />
<error statusCode="412" prefixLanguageFilePath="c:\inetpub\custerr" path="412.htm" />
<error statusCode="500" prefixLanguageFilePath="c:\inetpub\custerr" path="500.htm" />
<error statusCode="501" prefixLanguageFilePath="c:\inetpub\custerr" path="501.htm" />
<error statusCode="502" prefixLanguageFilePath="c:\inetpub\custerr" path="502.htm" />
</httpErrors>
strong textI need to display a custom 404 page to visitors when they attempt to visit an old article and redirect them to the new one. I have the following in the web.config for the site
<system.web>
<customErrors defaultRedirect="/custom404error.cfm" mode="On">
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/custom404error.cfm" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
When I run locally, Everything works great, however, I have ColdFusion 2016, and this project was written in ColdFusion 5. When I test on the proper servers, I hit a weird error, When the URL is something like www.domain.com/fakearticle.aspx my custom page pops up, however when the URL is www.domain.com/fakearticle.cfm or www.domain.com/fakearticle.htm, I get two different 404 error pages. My question is: Why am I getting 3 different error pages, and what can I do to my config file to fix this.
UPDATE Ive fixed it. I had some mixups between servers I was testing on. Deploying all my changes to the wrong server. It works as expected
Running ColdFusion 11 (Update 7) and IIS 7.5
My site application/root level web.config:
<configuration>
<system.webServer>
<httpErrors errorMode="Custom" />
</system.webServer>
</configuration>
My nested web.config file, which sits inside /api/eb :
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
When I visit a page that sits within the /api/eb sub-directory (e.g. 401.cfm) and trigger a 401 status code the server will return the Custom error handler response. My interpretation from the docs is that the nested web.config file should override the root web.config file but it clearly is not.
I've checked within the IIS applicationhost file and httpErrors overrideModeDefault is set to true. I also tried using a location tag within my root web.config file to do the same thing but it is also ignored unless I set the path to the wildcard character.
I'm out of ideas. Your help will be greatly appreciated. Thank you in advance.
I found this article which seems to explain your question pretty well - How to Use HTTP Detailed Errors in IIS 7.0
Specifically this excerpt:
Security Considerations
A word of caution: For architectural reasons, IIS can only execute the URL if it is located in the same Application Pool. Use the redirect feature to execute a Custom Error in a different Application Pool.
IIS can also return a 302 Redirect to the browser when a particular error occurs. Redirect is good if you have a server farm. For instance, you can redirect all your errors to a central location that you closely monitor.
There is risk however: responseMode="File" (which is the default) allows you to specify every file on the disk. This will not work if you are very security conscious.
A workable scenario might include only allowing the delegation of the errorMode setting. This enables a developer to receive Detailed Errors for his application even if he is using a remote client. All that is necessary is to set errorMode="Detailed". Here is how to configure this scenario:
Allow the delegation of the httpErrors section:
<section name="httpErrors" overrideModeDefault="Allow" />
Second, go to the section in applicationHost.config and change it so that only errorMode is delegated:
<httpErrors lockAllAttributesExcept="errorMode" lockElements="error">
<error statusCode="404" prefixLanguageFilePath="E:\inetpub\custerr" path="404.htm" />
<error statusCode="401" prefixLanguageFilePath="E:\inetpub\custerr" path="401.htm" />
<error statusCode="403" prefixLanguageFilePath="E:\inetpub\custerr" path="403.htm" />
<error statusCode="405" prefixLanguageFilePath="E:\inetpub\custerr" path="405.htm" />
<error statusCode="406" prefixLanguageFilePath="E:\inetpub\custerr" path="406.htm" />
<error statusCode="412" prefixLanguageFilePath="E:\inetpub\custerr" path="412.htm" />
<error statusCode="500" prefixLanguageFilePath="E:\inetpub\custerr" path="500.htm" />
<error statusCode="501" prefixLanguageFilePath="E:\inetpub\custerr" path="501.htm" />
<error statusCode="502" prefixLanguageFilePath="E:\inetpub\custerr" path="502.htm" />
</httpErrors>
Notice that the correct value for the overrideModeDefault attribute is Allow, not true as you mentioned in your question.
This article further explains the overrideModeDefault attribute - Understanding IIS 7.0 Configuration Delegation
Excerpt:
The overrideModeDefault attribute is an optional attribute that defines the locked state of a section. Its available values are either Allow or Deny. The default value is "Allow". All IIS sections that are related to any performance, security or critical aspect of the server are locked with this attribute set to "Deny". If the overrideModeDefault attribute is set to "Deny", then any configuration files at a lower level (i.e. web.config files) that set a value for a property for the specific configuration section are not able to take effect and override the global values. This incurs in a lock violation and an error occurs.
I have an Azure project with a single webrole that I am trying to get to run properly after upgrading to Windows 8 and Visual Studio 2012.
The problem is with any static content, it returns a HTTP 500 Internal Server Error with this text: "The page cannot be displayed because an internal server error has occurred." This error is presented for any static content (images and javascript), while dynamic content is served fine (all controller actions work fine).
We cannot get IIS to present a detailed error message. The only reference we can find to the error is in the access log, which presents it as a 500 subtype 19 error.
We've tried switching between IIS and IISExpress, same error occurs. We've tried adding all the "show detailed error messages" options to our web.config and IIS Manager. The same error happens on both HTTP and HTTPS endpoints.
What should be my next steps?
The culprit has been discovered. By comparing a default web.config with our web.config we discovered this in our web.config:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
</staticContent>
</system.webServer>
IIS8 has support for the WOFF built in, while IIS 7 did not. Simply moving this line into a transform solved the issue.
I came across this a long time ago and the answer from Vegard Larsen worked great. However, I've since upgraded to osFamily 3 (Windows Server 2012) and found that I was once again getting the 500 error with subtype 19 when deploying to Azure. The fix was to use the following in the transform.
<system.webServer>
<staticContent xdt:Transform="Insert">
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/x-woff" />
</staticContent>
</system.webServer>
The important part is to remove any existing .woff configuration. That way you can be sure it'll work on any IIS platform/configuration.