YAFLogo

McHine
  • McHine
  • 72.4% (Friendly)
  • YAF Forumling Topic Starter YAF Version: 4.0.0 RC4
a month ago
Hi Watcha, seems like it's been ages,

(Well aware that i'm overdue an actual listing of the board/site in your new board, but have been working on a major chunk (speaking of chunks have pulled a few of hair out))

How's it going?

So, I know i can easily get the User IP Guest or otherwise, but how?

Now i'm sure i saw that you expose the location information somewhere already, well have for previous iteration anyways..... how do I get that? Really IP country is fine, but city might be better. 

Cheers, appreciate that support!

Sponsor
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.1 BETA
a month ago
Well you can get the geo location from every user (including guests) from the active user page or the admin index 

 Bild_2025-06-13_091400089.png You have insufficient rights to see the content.

then you click on the ip address  and you will  taken to the ip info page.

McHine
  • McHine
  • 72.4% (Friendly)
  • YAF Forumling Topic Starter YAF Version: 4.0.0 RC4
a month ago
Ah, sorry for not being specific.

I need to call the IP and the geolocation of the IP into my code. 

what code do i need to use on my pages?

i can live with just the IP actually, but country and area/city would probably help me. 

might i ask how you are pulling the country and are/city? probably going to be using ip2proxy in anycase which will give me access to ip2location.

cheers!

tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.1 BETA
a month ago
Yes there is an API for that, which can be used on the Admin edit user profile page to get the country and city.

 var userIpLocator = await this.Get<IIpInfoService>().GetUserIpLocatorAsync(this.Request.GetUserRealIPAddress());​
McHine
  • McHine
  • 72.4% (Friendly)
  • YAF Forumling Topic Starter YAF Version: 4.0.0 RC4
29 days ago
Thanks, that's a good start, and should be enough, but.....

it would be great to have something similar to pull country or even more granular location detail (if it's available).

ie i would like to use country / city on my pages rather than visiting the admin edit user profile page.

Thanks a million!

tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.1 BETA
29 days ago

Thanks, that's a good start, and should be enough, but.....

it would be great to have something similar to pull country or even more granular location detail (if it's available).

ie i would like to use country / city on my pages rather than visiting the admin edit user profile page.

Thanks a million!

Originally Posted by: McHine 

I don't understand the problem. With the api you can use the location api on your pages.

McHine
  • McHine
  • 72.4% (Friendly)
  • YAF Forumling Topic Starter YAF Version: 4.0.0 RC4
27 days ago

Yes there is an API for that, which can be used on the Admin edit user profile page to get the country and city.

 var userIpLocator = await this.Get&lt;IIpInfoService&gt;().GetUserIpLocatorAsync(this.Request.GetUserRealIPAddress());​

Originally Posted by: tha_watcha 

that's my fault, i read that is it's all the IPaddress, not the 

IP address below

this.Request.GetUserRealIPAddress()

and the rest of it getting the location

i will see how that returns and use it from there, thank you very much, it's a great help!

McHine
  • McHine
  • 72.4% (Friendly)
  • YAF Forumling Topic Starter YAF Version: 4.0.0 RC4
26 days ago
Couldn't get that to work.....

is anyone surprised? :)

 YAFLOCATOR.jpg You have insufficient rights to see the content.

tried to step into this and couldn't.  var userIpLocatorResult = await yafIpService.GetUserIpLocatorAsync(testIP);

there's a step i'm missing i feel. connecting to an api or downloading a database?

I'm going to download ip2locator country only and will get me a bit of redundancy and self sufficiency, but let me know if i'm missing anything quick. not mega urgent, thanks a mill for the time and support.

text code if you want:

try

{

    // Use YAF's existing IIpInfoService

    using var scope = _serviceProvider.CreateScope();

    var yafIpService = scope.ServiceProvider.GetService();

   

    if (yafIpService != null)

    {

        // DIAGNOSTIC: Use fixed IP for testing

        var testIP = "102.165.86.118";

        _logger.LogInformation("DIAGNOSTIC: Using fixed test IP: {TestIP}", testIP);

       

        var userIpLocatorResult = await yafIpService.GetUserIpLocatorAsync(testIP);

       

        if (userIpLocatorResult != null)

        {

            // DIAGNOSTIC: Log the complete object structure

            _logger.LogInformation("DIAGNOSTIC: YAF IP Service returned object of type: {Type}", userIpLocatorResult.GetType().FullName);

           

            // Log all properties using reflection

            var properties = userIpLocatorResult.GetType().GetProperties(); 

tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.1 BETA
26 days ago
I forget in the host settings under Geolocation Settings  - IP Info Service needs to be enabled and under IP Info XML Web Service URL and the url needs to be set with an api key.

(Which is free for limited requests).