Request Request Routing: Get Source URL

I am trying to get the source URL from my application (MVC 5) after the reverse proxy has been rewritten.

I tried everything I could find, for example.

  • Setting my own server variable to {HTTP_HOST} (my server variable started with HTTP). This either contains the current URL or null.
  • Uses the HTTP_X_ORIGINAL_URL server variable, which does not include the host name.
  • View all built-in server variables.
  • Setting the value of preserveHostHeaders as described here: https://stackoverflow.com/a/464626/2/16 , which caused the site to freeze.

Any ideas?

Tried IIS7 and IIS7.5 with ARR 3.0 and Url Rewrite 2.0

+4
source share
1 answer

This answer is inspired by Configuring HTTP Request Headers and IIS Server Variables in IIS Documentation. They do something similar, but, oddly enough, this avoids detecting the original URL using HTTP or HTTPS.

First, you need to have administrative access to your IIS server in order to configure the new allowed server variable in the Rewrite URL module. This is described in a related article, but here are the basic steps:

  • In IIS Manager, browse to the website or application folder.
  • Open the URL Rewrite function.
  • In the Actions panel, click View Server Variables ..., then click Add ...
  • Enter a name for your server variable.
    • HTTP-, HTTP. , HTTP_X_MY_HEADER X-MY-HEADER.

rewrite {CACHE_URL}. web.config, .

. , .

<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> 

, . http://foo.example:80/bar, .

+2

All Articles