url rewrite and ARR across application pools - iis

I am trying to figure out how to use url rewrite and Application Request Routing (ARR) to rewrite across different app pools on the same server.
In a simplified version, here is what I have: a REST service API is implemented with 2 virtual directories, Service.A and B, so virtual directory is part of url to access to access resources A and B
GET [https://]api.mycompany.com/Service.A/A
GET [https://]api.mycompany.com/Service.B/B
What I want to achieve is to have one single external url for the api without virtual directory names, and obviously not having to go through a code refactoring (to merge solution files and builds)
GET [https://]api.mycompany.com/A
GET [https://]api.mycompany.com/B
I implemented a url rewrite rule to match /A in path and replace with /Service.A/A, with some code like this in web.config at the default web site level, which works fine.
<rewrite>
<rule name="AddServicePrefix" enabled="true">
<match url="^A[/]?.*" />
<action type="Rewrite" url="/Service.A/{R:0}" />
</rule>
</rewrite>
The problem is that when I assign a different application pool to Service.A (from the app pool of default web site), this will fail immediately with a 403 error, but this is a requirement on our side to have applications/virtual directories running under different app pools to minimize impact when any pool fails or recycles.
I have done some research. This previous post below basically said "if you want to re-route request to another app-pool, you have to make a hop, whether that hop is over winsock or named pipe or whatever else" without much details. I also went through ARR guide but couldn't figure out exactly how to use ARR for this case.
http://forums.iis.net/t/1151510.aspx?Rewrite+across+application+pools+
Any help? Suggestions and comments whether I am in the right direction?
Thanks!
oh, forget to mention the environment: currently in dev environment, IIS 7.5 on Windows 7, Url Rewrite 2.0, and ARR 3.0, installed by Web Platform Installer.

Related

http://localhost:port always redirecting to https://localhost

I'm building a simple website in vs2015. I have IIS express selected as the hosting environment. I have tried multiple new projects and seem to be going around in circles, having installed and uninstalled iis-express 10 multiple times, and added and removed windows feature of iis also. When I launch a web project from vs2015, it used to open (without issue) a http://localhost:port (e.g. http://localhost:51898), but now continually redirects to https://localhost.
Any idea why?
It is not about Visual Studio, it is about Chrome.
This solution worked for me: Google Chrome redirecting localhost to https
the redirect will only happen with explict configuration and IIS or
asp.net will not automatically redirect .
check following config files and loo for any redirect settings
ApplicationHost.Config,All web.config files (C:\Windows\System32\inetsrv\config)
search for httpRedirect
e.g. <httpRedirect enabled="true" destination="https://localhost" />
check for urlrewrite configurations. a typical rule will be like this .so you can search for Redirect
<action type="Redirect" url="http://www.maindomain.com/{R:1}" />
</rule>
If you do not find these settings anywhere in your configuration,your application code is doing this.Check your code
In my situation it was caused by this piece of code:
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
});
Anyway double check you startup.cs file. Maybe configurations there are part of a problem
in my case, it was a configuration i did on IIS for all my sites to load via https. The rewrite rule matched localhost as well and hence it redirects to https. I rewrote the redirect rule and it was ok.

Using IIS ARR to rewrite external URL

This might be a stupid question, however we have a website which we'll call http://example.com and we're using YuDu to publish some of our brochures online.
The URL's YuDu have given us are in the format http://content.yudu.com/htmlReader/SomeString/SomeName/SomeFile.html however we want to use our own URL's for these files:
i.e. http://example.com/ebrochure/SomeBrochure
I can setup URL rewriting for this, but it obviously redirects to the YuDu domain. Looking online it appears that I 'may' be able to use the IIS Application Request Routing module for this...but I'm at a loss as to how to do this. Everything I've found so far uses localhost and/or domains you already own for this.
So my question is:
Is my request even possible?
If so...could anyone point me in the right direction to do it?
Thanks in advance.
Matt
I don't think it's possible to do that. As far as the content must be served by yudu.com, you can only use redirections (with URL rewriting or by configuring a redirect in Application Request Routing). It will anyway end with a redirect. You could only manage this if yudu.com was one of your domains, which doesn't seem to be.
The only way I see if you really want to serve this content behind your example.com URL is using an iframe. But I don't know if Yudu will allow this.
Good luck !
It is definitely possible.
1) You need to install ARR module
2) In IIS manager you should enable reverse proxy
2.1) On server node click "Application Request Routing Cache"
2.2) Click "Server proxy settings" and click "Enable proxy", then "Apply"
3) In web.config add this rule:
<rule name="rewrite /ebrochure/SomeBrochure" stopProcessing="true">
<match url="^ebrochure/SomeBrochure$" />
<action type="Rewrite" url="http://content.yudu.com/htmlReader/SomeString/SomeName/SomeFile.html" />
</rule>
4) Open your url: http://example.com/ebrochure/SomeBrochure and you should see page from yudu

Application Request Routing: Get Original URL

I'm trying to get the original URL from within my application (MVC 5) after a reverse proxy rewrite has occurred.
I've tried everything I can find e.g.
Setting my own server variable to the value of {HTTP_HOST} (my server variable started with HTTP). This either contains the current URL or null.
Using HTTP_X_ORIGINAL_URL server variable which does not include the hostname.
Looking at all the built in server variables.
Setting the value preserveHostHeaders as detailed here: https://stackoverflow.com/a/7180527/4950, this caused the site to hang
Any ideas?
Tried on IIS7 and IIS7.5 with ARR 3.0 and Url Rewrite 2.0
This answer is inspired by Setting HTTP request headers and IIS server variables in the IIS documentation. They do something similar, but oddly it avoids detecting whether the original URL was accessed with HTTP or HTTPS.
First, you need to have administrative access to your IIS server in order to set up a new allowed server variable in the URL Rewrite module. This is described in the linked article, but here are the basic steps:
In IIS Manager, navigate to your web site or application folder.
Open the URL Rewrite feature.
In the Actions pane, click "View Server Variables...", then click "Add..."
Enter a name for your server variable.
If you want to access it as an HTTP header, prefix it with HTTP. For example, HTTP_X_MY_HEADER is accessible as the X-MY-HEADER header.
Then, in your rewrite rule, set the server variable value to {CACHE_URL}. You can do this through the UI, or directly in web.config, as shown below.
NOTE: be sure to set your match, conditions, and actions as needed.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="original URL sample" stopProcessing="true">
...
<serverVariables>
<set name="HTTP_X_MY_HEADER" value="{CACHE_URL}" />
</serverVariables>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The resulting header will explicitly include the port number, e.g. http://foo.example:80/bar, so you may need to deal with that depending on your needs.

IIS Url Rewriter rewrite fails but redirect works flawlessly

I have to set up a couple of apps on a new intranet server (Win 2008 R2 Standard SP1). I have been having some difficulty with a URL Rewriter rule. I had a similar rule working great on my local IIS (Win 7). The rule is designed to create a reverse proxy for a web service that enables jQuery AJAX requests from the client to avoid XSS.
The rule is as below and if I use this as is, and type an example URL into the browser:
http://srv01.domain.com/serviceproxy/workflow/Users/GetUsers?q=smith&max=10
I get a 404 response from the server. If I change the type to "Redirect" I get the response from the server expected (but obviously this will void my attempt to avoid XSS).
<rewrite>
<rules>
<rule name="Reverse Proxy - WCF Service" stopProcessing="true">
<match url="serviceproxy/workflow/(.+)" />
<action type="Rewrite" url="http://srv01.domain.com/WorkflowService/{R:1}" />
</rule>
</rules>
</rewrite>
Any ideas what might be missing from the server configuration? Is it a security setting somewhere that needs to be configured to allow the rewrite to occur?
I found my issue. I didn't have Application Request Routing installed on this server. Either I forgot installing it on my other server or it was already on there for another reason.
Found this article that helped me resolve it.
http://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing
Had a similar issue on Windows 2008, IIS 7.5
The problem was that the app pool was in integrated mode. that caused issues with the rewrite.
Redirect was always ok, but rewrite always failed.
changed the app pool to classic mode and problem solved (at least for now).
a better solution might be http://forums.iis.net/t/1200671.aspx?ARR+URl+Rewrite+is+not+working+for+external+servers
right at the end. but i havent tried it.

Urls /lpt1 and /com1 cause IIS to render its own screen of death

When running a recent SkipFish scan - we found that IIS (7.5) returns the following if you call /lptX or /comX (where X is a number 1-9).
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you ...[and so on]...
This is dispite the fact that we have custom [pretty] errors at the site-level and at the web server config level.
Try it on your IIS box now if you have one - http://localhost/lpt1 should do it.
I'm guessing this is a legacy thing from 'the good ol days' of LPT printers and mice connecting via COM ports. But it is slightly unsettling to see and area of IIS that I can't config.
Is it possible to force IIS to serve a custom 404 page even for these 'special' URLs?
Until ASP.NET 4.0 it wasn't possible to use certain reserved filenames such as con, lpt, aux and so in on your urls:
Zombie Operating Systems and ASP.NET MVC
This was a limitation of ASP.NET, not MVC.
However the good news is that it's now possible:
Putting the Con (COM1, LPT1, NUL, etc.) Back in your URLs
If you're not using ASP.NET 4.0, you should be able to catch these 404's using IIS7's own <httpErrors> configuration settings.
With ASP .NET 3.5 you can use an url rewrite rule of the url rewrite module in order to change the url to a valid one.
The url rewite module is:
The Microsoft URL Rewrite Module 2.0 for IIS 7 and above enables IIS
administrators to create powerful customized rules to map request URLs
to friendly URLs that are easier for users to remember and easier for
search engines to find
Something like:
<rewrite>
<rules>
<rule name="CON rewrite" stopProcessing="true">
<match url="(.*)/(con\.)(.*)" />
<action type="Redirect" url="{R:1}/con-{R:3}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>

Resources