Dynamics 365 Business Central: Where is cloud(SaaS) data actually stored (Get BC public IP address, City, Region, Country, Location etc.)

Dynamics 365 Business Central

Hi, Readers.
Yesterday, we discussed how to use Azure geographies to find where cloud(SaaS) data actually stored is. More details: Link. It is simple and intuitive, I highly recommend this method.
I got some feedback, and the information from Gonzalo Ríos Ley was very interesting.

So in this post, I will try out this advice.

First let’s take a look at the home page of ipinfo.
ipinfo.io: The Trusted Source for IP Address Data. With IPinfo, you can pinpoint your users’ locations, customize their experiences, prevent fraud, ensure compliance, and so much more.

When you open the website, it will display all the information about your current IP address.

So when you call ipinfo from the BC SaaS server, you should get the IP information like in your pc.

The next question is, how to use?
You can find the Getting Started in Docs menu. And all commands require TOKEN.

Okay, let’s try to sign up.

Only a little information needed.

Then you can get a token.

We can test the command in the command prompt.
For example:
curl -u 6*********: ipinfo.io

curl https://ipinfo.io?token=6*********

Next let’s do a small customization for Business Central.
The key method is to use HttpClient Data Type.
HttpClient Data Type: Provides a data type for sending HTTP requests and receiving HTTP responses from a resource identified by a URI.

This method is similar to the previous method of generating BarCode, using external service to return the required values. At that time it was a picture, this time only the text information is needed. (Of course you can also use Json)

I added a Get Ip button to the Company Information page.
Please replace Token with yours.

Test:
Country/region: US
Azure Region: South Central US

{
"ip": "23.101.184.73",
"city": "San Antonio",
"region": "Texas",
"country": "US",
"loc": "29.4375,-98.4616",
"org": "AS8075 Microsoft Corporation",
"postal": "78295",
"timezone": "America/Chicago"
}

Country/region: JP
Azure Region: Japan East

{
"ip": "20.89.61.117",
"city": "Tokyo",
"region": "Tokyo",
"country": "JP",
"loc": "35.6895,139.6917",
"org": "AS8075 Microsoft Corporation",
"postal": "101-8656",
"timezone": "Asia/Tokyo"
}

Test Video:

PS: You need to allow the extension to make HTTP requests through the HttpClient data type when you run the code.

Or you can enable Allow HttpClient Requests in Manage -> Configure of Extension Management page.

Source Code:

pageextension 50101 CompanyInformationExt extends "Company Information"
{
    actions
    {
        addfirst(processing)
        {
            action(GetIpInfo)
            {
                Caption = 'Get Ip Info';
                ApplicationArea = All;
                PromotedCategory = Process;
                Promoted = true;
                Image = GetOrder;

                trigger OnAction()
                var
                    Client: HttpClient;
                    HttpRequestMsg: HttpRequestMessage;
                    HttpResponseMsg: HttpResponseMessage;
                    URL: Text;
                    IpInfo: Text;
                begin
                    URL := 'https://ipinfo.io?token=6*********';
                    HttpRequestMsg.SetRequestUri(URL);
                    if not Client.Send(HttpRequestMsg, HttpResponseMsg) then
                        Error('Call failed');
                    HttpResponseMsg.Content.ReadAs(IpInfo);
                    Message(IpInfo);
                end;
            }
        }
    }
}

Price information of ipinfo: https://ipinfo.io/pricing

PS: In addition to ipinfo, there are other free services, such as http://ip-api.com/json.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

タイトルとURLをコピーしました