If your site uses geo-IP look ups to personalise the site extensively then you might find it tedious having to browse every page in edit mode then select the country/location visitor group you want to test with. I wanted to find a way to make it look like I was browsing from an IP address other than my development machine with a mimum of fuss.

Enter the IIS rewrite module. It is a useful and versatile add on for IIS7.x. Through configuration rules it allows you to modify incoming requests and outgoing responses for your site. One feature that is particularly powerful is the ability to modify incoming header values. 

So I have created a solution that allows you to spoof the incoming IP address of a user which will allow you to test geo-IP lookup personalisation as if you were in that country. In order to use the solution you must do two things:

1. Add the server variable that you want to modify (IIS > Click your site > URL Rewrite > Actions: View Server variables) as shown below: 

IIS Server variables

2. Add the following IIS rewrite module rule in web.config:

<system.webServer>
  ...
  <rewrite>
   <rules>
    <rule name="Spoof incoming IP address" 
          patternSyntax="Wildcard" stopProcessing="false">
     <match url="*" />
     <action type="None" />
     <serverVariables>
         <set name="REMOTE_ADDR" value="80.162.165.211" /> <!-- < The IP you want to spoof here -->
     </serverVariables>
    </rule>     
   </rules>
  </rewrite>
  ...
</system.webServer>

Obviously you must have the IIS Rewrite module installed before you can do any of this! Once you have added this rule you can enter any IP you like and browse your site as if you were coming from any IP in the world.

Requirements

Reference

Feedback

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


Comments