As we know by now EPiServer comes with a Geo-IP database built in which gives editors the ability to target content based on a location that is looked up from their IP address. However the geo-IP look up wont work properly if you are using a web acceleration service such as Akamai. This is because the originating IP will be that of the edge server, rather than the user's real IP.

I needed to ensure that EPiServer personalisation would work when using Akamai's web acceleration. The built in location based criterion used in Visitor Groups ultimately uses the "REMOTE_ADDR" server variable to get the user's originating IP address so this needed to be changed. Usefully Akamai normally passes the actual originating IP of the user in a custom variable called "True-Client-IP". So the requirement is simple, replace the REMOTE_ADDR server variable with the value from "True-Client-IP" and geo-IP look ups should all work fine.

In a previous post I described Using the IIS rewrite module to test EPiServer geo-IP look up personalisation.  So this post is simply an evolution of that rule. This is what I wanted to do:

  • Grab the incoming request
  • Look for the Akamai "True-Client-IP" header that contains something that looks like an IP address (if its not there then don't continue)
  • Replace the REMOTE_ADDR server variable with the value of True-Client-IP
  • Blank out the True-Client-IP value

In order to use the solution you must do two things:

  1. Add the server variables that you want to modify. See the instructions on my previous post on how to do this. Add REMOTE_ADDR and True-Client-IP as the server variables to modify.
  2. Use the following rule in web.config that implements the functionality I explained above:
<system.webServer>
   
  ...
 
  <rewrite>
    <rules>
      <rule name="Map true incoming IP address"
          patternSyntax="Wildcard" stopProcessing="false">
        <match url="*" />
          <action type="None" />
          <serverVariables>
            <set name="REMOTE_ADDR" value="{C:0}" />
            <set name="TRUE-CLIENT-IP" value="" />
          </serverVariables>
        <conditions>
          <add input="{HTTP_TRUE_CLIENT_IP}" pattern="*.*" />
        </conditions>
      </rule>
     </rules>
  </rewrite>
 
  ...
 
</system.webServer>
 
 

This solution should work if you are using Akamai as your web acceleration provider. I can't vouch for any other providers!

Testing

Obviously to test this I can't have Akamai pointing to my development box. So I used the Firefox add on Modify Headers to spoof the Akamai header.

Feedback

I'd be happy to hear any feedback on the comments below or @davidknipe


Comments

Recommendations for you