Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

Introduce a method to retrieve client IP address easily

Open petro2050 opened this issue 4 years ago • 4 comments

Getting the client IP address is not trivial. It'd be great if you could expose functionality to retrieve IP address information easily. I frequently log this info for every API request. I'm not sure if reading X-Forwarded-For will always be supported.

https://stackoverflow.com/questions/37582553/how-to-get-client-ip-address-in-azure-functions-c

Looking at the answers, it's clear that IP address retrieval is pretty messy.

petro2050 avatar May 22 '20 05:05 petro2050

X-Forwarded-For will only work if the client sets that header... Node.Js server, express, etc. out of the box provide a way to retrieve the client IP. It should be made available in the context object.

Falven avatar Jan 01 '21 19:01 Falven

For any future readers, I found out that Azure will always set the "X-Forwarded-For" header. It may not be available in local debugging, but on Azure it will be.

Falven avatar Jan 14 '21 11:01 Falven

Please let us know if this is yet to be triaged, so that I can route this issue to concerned team.

v-bbalaiagar avatar Jan 11 '22 15:01 v-bbalaiagar

When I updated to the lastest SDK the X-Forwarded-For header is no longer present on "Bring your own functions" for a static web app Also see: https://github.com/Azure/Azure-Functions/issues/2237#issuecomment-1930348682 Not being able to get the client IP address is pretty fundamental and means we can't move to dotnet 8

GrahamTheCoder avatar Feb 22 '24 13:02 GrahamTheCoder