We've done stuff like this in the past Dmitry:
public class CustomInitializationModule : Module
{
// Module class constructor, the system registers the module under the name "CustomInit"
public CustomInitializationModule() : base("CustomInit")
{
}
// Contains initialization code that is executed when the application starts
protected override void OnInit()
{
base.OnInit();
// Assigns custom handler to begin request event
RequestEvents.Begin.Execute += new EventHandler<EventArgs>(GetRealClientIpAddress);
}
void GetRealClientIpAddress(object sender, EventArgs e)
{
if ((HttpContext.Current != null) && (HttpContext.Current.Request != null))
{
var headers = HttpContext.Current.Request.Headers;
// look for the special header variable that the firewall or load balancer passes
var realIP = headers.Get("SPECIAL HEADER VALUE"); //Make sure to change this to real value
if (!String.IsNullOrWhiteSpace(realIP) && (realIP != "::1"))
{
RequestContext.UserHostAddress = realIP;
}
}
}
}