Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > GetCountryByIp works but GetCountryIDByIp does not? View modes: 
User avatar
Member
Member
matt-awg - 4/30/2013 9:31:46 PM
   
GetCountryByIp works but GetCountryIDByIp does not?
Any ideas why this:

ValidationHelper.GetInteger(CMS.WebAnalytics.GeoIPHelper.GetCountryIDByIp("XX.X.XXX.XX"), 0)

returns 0

but this:

ValidationHelper.GetString(CMS.WebAnalytics.GeoIPHelper.GetCountryByIp("XX.X.XXX.XX"), "")

returns "United States"?

In both cases "XX.X.XXX.XX" is the same hard coded IP address I am using just to test this. The API documentation for GetCountryIDByIp states "Finds ID of country from CMS_Country table by IP4 address." which is exactly what I want, but I cant' figure out why it works by name and not IP. Does the GetCountryByIp method not look in that table and if not, then where is it getting the name from? I don't see any errors in the event log and my code does not raise any errors on the page. I thought maybe it was some licensing issue because I am not running EMS, I am running Ultimate, but wouldn't an error show in the event log and also, why would one of these be included in my license and not the other?

Thanks,
Matt

User avatar
Kentico Support
Kentico Support
kentico_filipl - 5/2/2013 2:15:35 AM
   
RE:GetCountryByIp works but GetCountryIDByIp does not?
Hello Matt,

I tried the methods you mentioned and they were working as expected with the latest hotfix. When I passed USA IP address to GetCountryIDByIp() method, the result was ID 271.

Could you try the method with this IP address and see if it works correctly for you?
ValidationHelper.GetInteger(CMS.WebAnalytics.GeoIPHelper.GetCountryIDByIp("174.76.228.35"), 0)

If it does not, please apply the latest hotfix.

Please let me know if this suggestion helps.

Best regards,
Filip Ligac

User avatar
Member
Member
matt-awg - 5/2/2013 11:21:13 PM
   
RE:GetCountryByIp works but GetCountryIDByIp does not?
I tried the IP you provided, I even copy and pasted your line of code to make sure and it still returns zero. I even applied the hotfix 32 (that is cumulative right? I only need to apply the latest or should I have done each one at a time?) and still have the same result. I then changed the zero default in the GetInteger call to be -1 but it still returns zero.

Also, I realized I had localized the country display name so I removed that and tried again, still no luck. Then I tried changing the name in the country display name field for ID 271 to something and re-ran it with the GetCountryByIp and it does not return the new name. Where does the country name value come from when you call GetCountryByIp? I guess not the CMS_Country table since it did not match what was in there.

Then it hit me, I am using the "Country 2-letter code" field for a special purpose in a custom control I built - a blank value in there has a special meaning in my control and so the US had been removed. Apparently this causes the GetCountryIDByIp to fail because when I put US back in there, suddenly it returned 271. I assume it is using that field to join to whatever IP lookup table it is using? This stinks... now I have to re-do my custom control using a different field. Why wouldn't it use the "Country code name" to do a look up? Do you know if the "Country 3-letter code" is also used by some other process that will get messed up if I change it? And this should really be documented so people don't make this mistake again or that field should be read only maybe so it does not break the lookup don't you think?

Thanks,
Matt

User avatar
Kentico Support
Kentico Support
kentico_filipl - 5/3/2013 3:13:51 AM
   
RE:GetCountryByIp works but GetCountryIDByIp does not?
Hi Matt,

GetCountryIDByIp() method and all other methods from GeoIPHelper namespace use data from CMS_Country database table. If you look at the records there, they should correspond with results the methods give.

Additionally, probably all methods use CountryThreeLetterCode as parameters so if you change your custom control to use this column, it should not affect any other process.

We realize API documentation is quite confusing sometimes but it should be improved with the release of Kentico CMS 8.

Best regards,
Filip Ligac

User avatar
Member
Member
matt-awg - 5/6/2013 6:28:10 AM
   
RE:GetCountryByIp works but GetCountryIDByIp does not?
Hi Filip,
Thanks for the reply. I have some more questions:

1) when you said:

"Additionally, probably all methods use CountryThreeLetterCode as parameters so if you change your custom control to use this column, it should not affect any other process."

Did you mean "two" not "three"? I assume that is what you meant since the "two" letter code was causing my problem but just wondering if you can confirm that the three letter code is not used by any internal Kentico functions so if I use that for a custom purpose it will not break anything.

2) I am not sure I like this approach because even if your answer to my question 1 above is that I can use the three letter code field for a custom purpose, I worry about that breaking something if in a future release you guys use it for something. SO, I looked into adding a field to that system table but I am not sure that will work. I found this thread:

http://devnet.kentico.com/Forums.aspx?forumid=45&threadid=16556

but it is for version 5 and the instructions for modifying the site manager section don't match version 7. I was able to find the relevant files in version 7 but I don't see how I can use Get/SetValue as there seems to not be any code in the code behind, for example, here is the New.aspx.cs code:
// Breadcrumbs
[Breadcrumbs(2)]
[Breadcrumb(0, "Country_Edit.ItemListLink", "List.aspx", null)]
[Breadcrumb(1, "Country_Edit.NewItemCaption")]
// Title
[Title("Objects/CMS_Country/new.png", "Country_New.HeaderCaption", "new_country")]
public partial class CMSModules_Countries_Pages_Development_Country_New : SiteManagerPage
{
}

Also, I noticed if I run this SQL:
UPDATE dbo.CMS_Class SET ClassShowAsSystemTable = 1 where ClassTableName ='cms_country'

It does add the country table to the system tables admin section in site manager but as soon as I save a change, Kentico seems to set this field back to 0 on me! Is this not something that you can do in version 7? Should I just use the three code field as a custom field? I just hate doing it that way, it seems sloppy, and what if I end up needing two fields. It would be cleaner to add a custom field(s) to the system table if this is possible in version 7. Please let me know and if possible, give me an idea on how to do so in version 7.

Thanks,
Matt

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 5/6/2013 7:41:22 AM
   
RE:GetCountryByIp works but GetCountryIDByIp does not?
In regards to the CMS_Country table in Site Manager, yes you should be able to simply run the query you provided and perform actions to the CMS_Country table in the Site Manager. I've done this for a few clients for this exact table without issue. There should be no need to modify any physical files for this to work as you expect.

User avatar
Member
Member
matt-awg - 5/6/2013 7:46:53 AM
   
RE:GetCountryByIp works but GetCountryIDByIp does not?
FroggEye,
I did run the query, it allowed me to add a field via site manager but the new field does not come up in the form to add/edit a country. And as I said, when I add a field to that table via site manager, Kentico flips that flag on the class table back to zero so it no longer shows up in the system table admin section unless I go back and rerun the query.
Thanks,
Matt

User avatar
Member
Member
matt-awg - 5/6/2013 8:19:15 PM
   
RE:GetCountryByIp works but GetCountryIDByIp does not?
FroggEye,

Just to clarify, when you said you have done this before, did you just mean adding fields via site manager -> development -> system tables? Because I am able to add a new field after I run that query. That is not my problem, I need to then give admins the ability to set the value for this new field.

After adding the fields, were you then able see the new fields on the form when using site manager -> Development -> countries (and populate values in the fields successfully)? I tried clearing my cache and even restarting the application but I don't see an input for the new field I added. What version of Kentico was this in? I am running 7.0.32

Thanks,
Matt

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 5/8/2013 11:28:50 PM
   
RE:GetCountryByIp works but GetCountryIDByIp does not?
Matt,

I've done this on several system tables and have never had it "switch" back after performing updates within the UI. One table was countries, another is states. There are a few others but I don't remember off hand which ones, maybe tags or categories. They were on various versions of 7. 7.0, 7.18, 7.32

You might need to double check that properties attributes and ensure it checked to show in form. Also if you are using alternative forms, ensure you have that new field added to the alternative form.

Brenden

User avatar
Kentico Support
Kentico Support
kentico_filipl - 5/10/2013 9:09:06 AM
   
RE:GetCountryByIp works but GetCountryIDByIp does not?
Hi Matt,

Here are the instructions for adding a custom field to CMS_Country database table which should be also reflected in Site Manager -> Development -> Countries (I think you have already done the first 2 steps).

1) Set the ClassShowAsSystemTable column for the cms.country [ClassName] row in the CMS_Class table to True to display the Country table in the UI.

2) Add a new field into that table in the Site Manager -> Development -> System tables -> Country -> Fields section.

3) Edit the ~\CMSModules\Countries\Pages\Development\Country\List.aspx file and add there your new column specification - for example:
<ug:Column Source="CountryDisplayName" Caption="$Unigrid.Country.Columns.CountryDisplayName$"
Wrap="false" Localize="true">
<Filter Type="text" />
</ug:Column>
<ug:Column Source="CountryFlagPath" Caption="Flag" Wrap="false" Localize="true">
<Filter Type="text" />
</ug:Column>
<ug:Column Width="100%" />

4) Edit the ~\CMSModules\Countries\Pages\Development\Country\Tab_General.aspx file and add your new column there as well:
<cms:FormField runat="server" ID="fDisplayName" Field="CountryDisplayName" FormControl="LocalizableTextBox"
ResourceString="Country_Edit.CountryDisplayNameLabel" Trim="true" />
<cms:FormField runat="server" ID="fCountryName" Field="CountryName" FormControl="TextBoxControl"
ResourceString="Country_Edit.CountryNameLabel" Trim="true" />
<cms:FormField runat="server" ID="fCountryFlagPath" Field="CountryFlagPath" FormControl="TextBoxControl"
ResourceString="yourResourceString" Trim="true" />
<cms:FormSubmit runat="server" ID="fSubmit" />

Best regards,
Filip Ligac

User avatar
Member
Member
matt-awg - 5/12/2013 6:25:12 PM
   
RE:GetCountryByIp works but GetCountryIDByIp does not?
Hi Filip,
That did it.
THANKS!
Matt