Hi Saurabh Sutone,
Thank you for posting in the Microsoft Community Forums.
IIS Configuration
Enable advanced logging:
IIS's advanced logging feature allows you to customize log fields, including adding X-Forwarded-For (XFF) header information. This helps you log the original IP address after it has gone through a proxy or load balancer.
Start IIS Manager and click on the server name on the left.
On the home page, double-click “Advanced Logging” under “IIS”.
Click “Enable Advanced Logging” in the right action pane.
Click “Edit Logging Fields” to add a new field, enter “ClientSourceIP” for the Field ID, and select “Default” for the Category. “Default”, select ‘RequestHeader’ for Source type and ‘X-Forwarded-For’ for Source name. “.
Add a log definition and select the “ClientSourceIP” field you just added.
Apply the settings and restart IIS.
Make sure the X-Forwarded-For header is passed correctly:
If your site is deployed behind a load balancer or WAF appliance, you need to make sure that these devices are configured to pass the X-Forwarded-For header. This usually requires enabling X-Forwarded-For data forwarding in the device's configuration.
Windows Server OS Configuration
At the Windows Server OS level, you may need to ensure that IIS has permission to read and log X-Forwarded-For headers. This is usually not a required additional configuration, as the advanced logging features of IIS already provide this capability. However, if you run into permissions issues, you may need to check the permissions settings of your IIS application pool.
Third-party plug-ins or modules
If IIS's advanced logging features don't cut it, you can also consider using a third-party plug-in or module to log X-Forwarded-For header information. These plug-ins or modules usually offer more advanced features and customization options.
Caution.
Before making any configuration changes, make sure you have backed up your existing IIS configuration and log files.
If your site uses HTTPS and you want to log information about encrypted requests in your logs, you need to make sure that your load balancer or WAF appliance supports SSL offloading or termination so that IIS can access the raw request header information.
Monitoring and logging features may incur additional storage and performance overhead. Therefore, consider your Azure VM's storage and performance limitations when enabling these features.
Best regards
Neuvi