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:
Related
I'm trying to redirect in case of an http error to a error page hosted in an external url making use of the element <httpErrors> in my web.config file in server.
Currently I have the following configuration
<configuration>
<system.webServer>
<httpErrors errorMode="Custom" defaultResponseMode="Redirect">
<error statusCode="404" path="https://my-custom-error-page.com" />
</httpErrors>
...
and whatever I set as defaultResponseMode I cannot get the error page, and instead I'm still retrieving always the IIS error page.
someone knows what's missing?
IIS version 8.5
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/httperrors/
Redirecting to custom error pages in Azure Application service doesn't work
Make sure your web.config is deployed in the wwwroot directory
Iam able to redirect to CustomError page with the below setting in web.config when an error occurs
<httpErrors existingResponse="PassThrough" />
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/public/404.html" responseMode="ExecuteURL" />
</httpErrors>
Under <system.webServer> , Make sure you add
<httpErrors existingResponse="PassThrough" />
Check the path correctly
Under wwwroot folder created one folder named public and added the error.html page. Give the same path /public/404.html in web.config
Tried to access the page which does not exists, it redirected to the error page
Is there a specific setting in IIS to get the error page handling to work right if you enter a url that ends with "/"? On my local machine, if I navigate to
http://localhost:20640/herbitty/blerb.aspx
OR
http://localhost:20640/herbitty/
http://localhost:20640/herbitty/?somehorriblequerystring=oops
These pages redirect to Default.aspx as they should. But after i've deployed to the server, only the pages ending with .aspx work properly. The pages ending with a slash end or a random static content (http://my.dev-server.org/ls/ls.html) up on a completely white page, with no html or anything.
Here is my web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="/Default.aspx" />
</system.web>
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode='-1' />
<remove statusCode="503" subStatusCode='-1' />
<!-- this catches everything that is not Default.aspx-->
<error statusCode="404" path="/Default.aspx" prefixLanguageFilePath="" responseMode="ExecuteURL" />
<!-- 503 needs to redirect because this is set manually on the Default.aspx page-->
<error statusCode="503" path="/Default.aspx" prefixLanguageFilePath="" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
My server did not have the following roles added to it:
Web Server -> Common HTTP Features -> HTTP Errors
Web Server -> Common HTTP Features -> HTTP Redirection
Now I get a proper 404 error page, so i can now catch it.
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 ;)
I'm trying to configure the default webpage for an IIS 7.5 website.
Request filtering is turned on. However .aspx pages are allowed, I've set default.aspx to be the default page for the website.
If I browse to localhost/default.aspx I get a webpage as expected.
IF I browse to localhost/ I get
HTTP Error 404.7 - Not Found
The request filtering module is configured to deny the file extension.
Any ideas?
It looks like the request filtering is actually filtering for a blank file name. Therefore you have to add this to the request filtering block in the web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<fileExtensions allowUnlisted="true">
<remove fileExtension="." />
<add fileExtension="." allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>
</configuration>
It's obvious now, but really I think its a massive gotcha.
More info: IIS 7 Not Serving Files - 404.7 Error
You can resolve by adding:
<requestFiltering>
<fileExtensions allowUnlisted="true">
<remove fileExtension="." />
<add fileExtension="." allowed="true" />
</fileExtensions>
</requestFiltering>
to your Web.Config file
You can resolve this by adding the file extension into the request filtering module of IIS.
Be sure to remove any PostBackURL="MyPage.aspx" from the button on the page. My guess is that when the postbackurl is included, IIS thinks its getting the page as a file. It rejects the .aspx file type by default. You can see this in the page error.
Bad: Creates a 404.7 (notice the PostBackURL)
<asp:FileUpload runat="server" ID="uplReplaceFile" ToolTip="Update this file" />
<asp:Button runat="server" PostBackUrl="MyPage.ascx" ID="bnHiddenFileUploadListener" OnClick="bnHiddenFileUploadListener_OnClick" />
Good: No error
<asp:FileUpload runat="server" ID="uplReplaceFile" ToolTip="Update this file" />
<asp:Button runat="server" ID="bnHiddenFileUploadListener" OnClick="bnHiddenFileUploadListener_OnClick" />
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.