Using custom error pages with ARR / Application Request Routing - iis

How can I display custom HTML instead of the following 502 response from ARR?
Traffic is directed to the server farm using a URL Rewrite rule on the server level.

Open IIS and then on the server level, in the IIS section, click "Error codes". These files are global, which is the level you will want to change for your situation. There are also site level error pages. You can modify these files or you can point them to a different file that you have customizedIIS Error Pages.

Related

Application Request Routing: Why some sites return HTTP 404 some don't?

I want to add a load balancer to an existing asp.net project using Application Request Routing. So I made myself familiar with the concepts and created a local test-setup:
IIS locally running on Windows 10:
Installed Application Request Routing 3.0 with Windows Platform Installer
Created server farm with following servers:
<test-server-name>.de (Microsoft 2012 R2 Server: contains the asp.net project)
www.google.com (just to see if load balancing and url rewriting works because I don't have two test servers available)
URL-Rewriting rule:
After typing localhost multiple times in any browser, I can see that load balancing (weighted round robin) is working fine. It's alternating between 1. and 2. website.
The problem I'm facing is a 404 Error on both websites.
I already tried the following:
Installing and enabling Failed Request Tracing Rules (on local IIS): URL Rewriting is working properly i think.
Failed Request Log for www.google.com: google drive, unzip and open xml in e.g. IE for better view
Create Server Farm without automatic creation of URL Rewrite rules
(selecting No and create own URL Rewrite rule)
Change "Managed Pipeline Mode"-setting of Applcation Pool from Integrated to Classic
Healthcheck on other Websites I have absolutly no clue why it's working on Git-websites and why facebook is returning a 400 error code.
Enabling/disabling proxy (IIS-Manager -> Application Request Routing Cache -> Server Proxy Settings...)
I don't know what i could do next, so I appreciate any help. Thanks.
Answer can be found here: https://forums.iis.net/t/1238739.aspx?Why+some+sites+return+HTTP+404+some+don+t+
Some websites simply don't support localhost as hostname, which is why localhost can't be found (error 404) e.g. on google.com
Detailed answer if link above is not working in future:
That is not an effective test.
What you are doing is sending the hostname of your request to the third party servers. Like Google.
So if your request is say http://example.com you are sending this to say www.google.com and the Google servers will likely reject this as you can see
Web server admins generally don't let themselves receive traffic from domain thet do not host.
If you sent a request to my servers IP with mysite.com I too would likely reject it. (Things get complex if you have wildcard sites and you allow all traffic through)
But simply showing that 404 page from Google means tour request hit there server so that implies ARR is working.
If you really wanted to test it this way have a local host file with www.google.com resolving to your servers IP. Set up a site with www.google.com as the hostheader and then you should see the correct info hitting Google. But there is no accounting for what 3rd party admins do on their side.

IIS URL Rewrite - how to see rewritten URL?

In IIS I've set up a basic URL Rewrite with an Inbound rule to perform a Rewrite action to another domain:
Pattern match: ^somedirectory/(.*)
Action type: Rewrite
Rewrite URL: http://www.google.com/{R:1} (using google just as a test)
The problem is, how can I actually see what the server has rewritten the URL to? When I check the IIS logs (I have "Log rewritten URL" option ticked), I would expect to see www.google.com somewhere - but it's nowhere to be found.
The pattern is definitely matching because I get the error: "502 - Web server received an invalid response while acting as a gateway or proxy server."
How can I see what is going on behind the scenes (how IIS has changed the request)?
One way is to enable "Failed Request Tracing" is IIS.
For the status code choose a range like 100-999 to capture all requests (even non-failing).
IIS will create an XML file for each request to a log directory. The XML can be viewed nicely within Internet Explorer (try the compact view tab).

Http 403 error in Microsoft edge

I was getting "HTTP 403 error Microsoft Edge can’t get to this page", while launching an application from IIS in Windows 10. Please suggest a solution for this.
thanks
If all permissions are set and even though your website shows 403 forbidden, most likely the default page is not set for your website. With IIS, you can configure the default document as follows.
Connect to IIS.
Expand the sites and select the desired website.
From right hand side feature view, click on Default Document.
Set your desire default page and save the settings.
While you browse any website, IIS searches for the default page to be displayed. If the first default document is not available, IIS will look for the next default page from the list. When IIS is unable to find any match and directory listing is enabled for that particular website, IIS will show you the list of folders. If directory listing is disabled, IIS will return an HTTP Error 403 - Forbidden message to the browser.
If an empty application gives you a 403 I can think of two immediate reasons.
The permissions are wrong. You might need to give the application pool user (IIS AppPool\NAMEOFAPPPOOL with recommended configuration) read permission to the directory.
You don't have any content. If you try to access a directory in IIS you will get a 403. Add a file and try to access that directly, or a Default.aspx or index.html file to the directory you're trying to access.

Open a web application when request is made to IIS server root

Using IIS7, I have a web application (lets say it is called "MyWebApp" installed under "Default Web Site", on my web server (lets say it is called www.mywebserver.com)
What I want to achieve is that when a browser makes a request to www.mywebserver.com, I want to open MyWebApp, as if the request was www.mywebserver.com/MyWebApp.
How do I achieve this?
Do a redirect, there are several ways to do that:
Add an html page with a meta refresh
Use ASP .NET Redirection methods (Response.Redirect and Server.Transfer)
Use IIS Redirect
I'd recommend the IIS Redirect. Follow these steps:
Open IIS Manager and navigate to the level you want to manage.
In Features View, double-click HTTP Redirect.
On the HTTP Redirect page, select Redirect requests to this destination. In the corresponding box, type the file name, directory path, or URL to which you want to redirect the user.
In the Actions pane, click Apply.

IIS 404 Custom Error: URL return response code 200 instead

I'm trying to return a custom 404 page using IIS6. (I have a site that is mostly .shtml pages built using movable type). I have tried it 2 ways:
1) set the 404 error handler in IIS to be type "file" with the path \404.html. This works, but it also means that I can't import the header and footer of my site (hence the .shtml) Trying to point the 404 error handler to 404.shtml results in the default 404 page...i guess IIS can't process shtml files in the 404.
2) set the type to "URL". This works great, except that the response code is no longer 404! Its a 200.
How can I get IIS to respond with a 404 response code with the content of my 404.shtml file?
Given that it's IIS, adding
<% Response.Status = "404 Not Found" %>
to the top of 404.shtml should change the response code to 404.
I am not on a windows machine so I am unable to test it at the moment to verify.
Update:
I was finally able to run a few tests on a IIS 6. As you mentioned in a comment to my post, an .shtml file does not allow script commands to run. So there are at least two ways to work around this:
Instead of naming your custom 404 handling page 404.shtml, name it 404.asp. The user should never see the actual name of the page so it shouldn't cause any issues. Note that "Active Server Pages" must be set to 'Allowed' in the Web Service Extensions folder of IIS.
Modify the page extension mapping for .shtml to use asp.dll instead of ssinc.dll. You can do this from IIS by selecting the website and viewing Properties -> Home Directory tab -> Configuration -> Mappings tab. Note that this is far from an ideal solution because now all your .shtml files will be processed by asp.dll. This could cause your pages to render more slowly (assuming asp.dll processes files more slowly than ssinc.dll due to greater complexity) and violates the principle of least privilege.
If neither of the options fit your situation, then it may still be possible but the solution isn't immediately obvious to me.
In IIS Manager, open the Properties of your Web site (or virtual dir) and go to the Custom Errors tab. There you can set which file is sent in case of each error code, including 404.

Resources