« Previous Next »

Thread: URL Rewrite 2.0 and REMOTE_ADDR

Last post 10-19-2009 5:36 PM by ruslany. 8 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (9 items)

Sort Posts:

  • 09-21-2009, 9:43 PM

    • gpduck
    • Not Ranked
    • Joined on 09-22-2009, 1:14 AM
    • Posts 5

    URL Rewrite 2.0 and REMOTE_ADDR

    I'm trying to find a solution to allow the client IP to be preserved using an X-Forwarded-For header from our hardware load balancer.  I would like to get this working with URL Rewrite 2.0 as this will be the most supportable option once v2.0 is released, but I'm having trouble getting the REMOTE_ADDR variable to be overwritten.

     I can successfully write the X-Forwarded-For value to a new HTTP_variable:

    <set name="HTTP_Test" value="{HTTP_X_Forwarded_For}" replace="true" />

    But when I try to set the REMOTE_ADDR variable, nothing happens:

    <set name="REMOTE_ADDR" value="{HTTP_X_Forwarded_For}" replace="true" />

    What am I missing here?

  • 09-24-2009, 7:04 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: URL Rewrite 2.0 and REMOTE_ADDR

    What do you mean when you say nothing happens?  Does getting the REMOTE_ADDR server-variable still gives you the non-rewritten value?  Also, look at this blog post.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 09-24-2009, 7:54 PM In reply to

    • gpduck
    • Not Ranked
    • Joined on 09-22-2009, 1:14 AM
    • Posts 5

    Re: URL Rewrite 2.0 and REMOTE_ADDR

    I meant that the module is not doing anything to the value of REMOTE_ADDR, so the variable still returns the IP address of the load balancer.

     I have played around with your ARR helper module before, but I was hoping that URL Rewrite v2 would work so that when we eventually move this to our production servers we would be using an official Microsoft module that would be supported by the IIS team.

  • 10-12-2009, 4:43 PM In reply to

    • gpduck
    • Not Ranked
    • Joined on 09-22-2009, 1:14 AM
    • Posts 5

    Re: URL Rewrite 2.0 and REMOTE_ADDR

    So is this a bug, or is it not intended that we can change the REMOTE_ADDR variable using the URL Rewrite module?

  • 10-12-2009, 9:21 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: URL Rewrite 2.0 and REMOTE_ADDR

    But, how are you verifying whether or not REMOTE_ADDR has changed or not - is it via some asp/asp.net code on your site?

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 10-13-2009, 2:24 AM In reply to

    • gpduck
    • Not Ranked
    • Joined on 09-22-2009, 1:14 AM
    • Posts 5

    Re: URL Rewrite 2.0 and REMOTE_ADDR

    Yes, I'm printing out all the server variables in an ASP page.  I am able to create a new variable, like HTTP_foo, and set that equal to the value in the x-forwarded-for header, but I cannot get anything to overwrite the REMOTE_ADDR header (either with the dynamic value from x-forwarded-for or just static text entered into the rewrite rule).

  • 10-15-2009, 1:16 AM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 661

    Re: URL Rewrite 2.0 and REMOTE_ADDR

    Can you provide the rule and the asp code to repro this?

    I tried this rule:

    <rule name="test">
        <match url="(.*)" />
        <serverVariables>
         <set name="REMOTE_ADDR" value="::2" replace="true"/>
        </serverVariables>
    </rule>

    And this asp code:

    <p>REMOTE_ADDR is <%= request.servervariables("REMOTE_ADDR") %></p>

    And it worked correctly.

    Note that the server variable names are case sensitive.

    http://ruslany.net
  • 10-15-2009, 7:50 PM In reply to

    • gpduck
    • Not Ranked
    • Joined on 09-22-2009, 1:14 AM
    • Posts 5

    Re: URL Rewrite 2.0 and REMOTE_ADDR

    I just deployed a fresh VM image of my test server to make sure I hadn't done anything to the IIS config to screw this up.  This is on a fresh 2008 x64 image with SP2 applied.

     Here is my web.config:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
    <rule name="test">
        <match url="(.*)" />
        <serverVariables>
         <set name="REMOTE_ADDR" value="::2" replace="true"/>
         <set name="HTTP_FOO" value="Hello" replace="true"/>
        </serverVariables>
    </rule>

                </rules>
            </rewrite>
        </system.webServer>
    </configuration>

    And here is the ASP:

    <html>
    <head>
    <title>boo</title>
    </head>
    <body>
    <p>REMOTE_ADDR is <%= request.servervariables("REMOTE_ADDR") %></p>
    <p>Foo is <%= request.servervariables("HTTP_FOO") %></p>
    </body>

     And here is my output the first time I hit the page (the IP returned is that of our load balancer):

    REMOTE_ADDR is x.x.x.x

    Foo is Hello

    What is weird is that if I refresh the page the "Hello" drops off, until I recycle the app pool.  If I define the rule in the applicationHost.config instead of web.config I get the same result as far as the IP address but the "Hello" does not drop off after one request.

    I don't see any errors in the application or system logs when I have the rule defined in web.config, but I did get a sxs error when I installed URL Rewrite:

    Activation context generation failed for "C:\Windows\system32\inetsrv\rewrite.dll". Dependent Assembly Microsoft.VC90.CRT,processorArchitecture="amd64",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.30729.1" could not be found. Please use sxstrace.exe for detailed diagnosis.

    I checked and that assembly is in my c:\windows\winsxs folder.

  • 10-19-2009, 5:36 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 661

    Re: URL Rewrite 2.0 and REMOTE_ADDR

    I tried to repro this with the beta build on a Win2k8 x64 machine, but exact same rule and the asp page produced the correct result.

    The problem with "Hello" dropping off is a known bug that will be fixed in the upcoming release of the URL Rewrite 2.0.

    http://ruslany.net
Page 1 of 1 (9 items)
Microsoft Communities