This project is read-only.

ISAPI Filter to modify request server variable

Apr 15, 2009 at 3:35 PM
Hi Tiago,

               Before posting my question, I would like to thank you for providing a cool framework for writing ISAPI filters. I installed framework on my local machine and tried few of your sample apps and everything works fine. Here is my situation.....

              In our environment, any incoming request comes through a Load Balancer and as a result, the client IP address that gets stored in the IIS log file is that of the Load Balancer and not the actual client's IP address. The "X-FORWARDED-FOR" header which holds the actual client IP address is passed along with the request . 

             In short what I would like to achieve is write an ISAPI filter that would replace the "REMOTE_ADDR" server variable value ( Load Balancer's IP address value) with the value from the "X-FORWARDED-FOR" header. I am subscribing to the PreProcHeaders event to retrieve the header values, but I am unable to change the "REMOTE_ADDR" server variable value as it is read only.

By doing so I am hoping that when IIS logs the request to the log file, the c-ip value would be the correct client's IP address. Would really appreciate your help in this matter.

Codeplex user.
Apr 18, 2009 at 6:37 PM


Thanks so much!

As for your question, seems you have a reverse proxy in place, not a router. IIS records the IP address used to connect to it in REMOTE_ADDR, one of its internal contextual properties. IIS provides server variables, which are read only, as a collection of IIS internal contextual properties and request headers.

You may, however, subscribe to the managed Log event (native SF_NOTIFY_LOG event) and replace the client hostname. Read more here: Let me know how it goes.

Tiago Halm

Apr 19, 2009 at 3:29 PM
Hi Tiago,

                 Thanks for your response. That is exactly what I did to log the actual client IP address.

a)Subscribe to the PreProcessHeader and the Log events.
b)Retrieve the client IP address from the "X-FORWARDED-FOR" header in the PreProcessHeader event handler and store it in the filter session.
c)Finally in the Log event handler, get the value from the filter session and update the client hostname.

Codeplex user.