Usama Aslam
Usama Aslam

Reputation: 1

how to get user current location in web based bot using direct line c#

I am working on a bot in which I have to display offers to the user according to their current location. I use this method to get the user's IP address :

String ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(ip))
{
   ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}

But the IP address that code fetches is totally wrong.

What is the correct method to get the user's IP address in bot framework C#?

Upvotes: 0

Views: 455

Answers (1)

Steven Kanberg
Steven Kanberg

Reputation: 6368

Please look over this project I created not too long ago. It uses botchat.js in a webpage to instantiate a bot and implements backchannel to pass values to and from. The project shows how to use the browser's IP address or a paid service (ipstack.com, in this case) to determine a user's location. The main.js file is where most of the magic happens.

I haven't had a chance to write a proper readme file. If you have any questions, let me know.

Hope of help!

Upvotes: 1

Related Questions