Calling Google Place APIs from ASPNet Core Web App code

Hi,

To call Google Place API, construct a URI string with example below, to call nearbysearch API

And then create a code similar to below to call the API, get the response and transform it to JSON format

                try
                {
                    HttpResponseMessage response = await client.GetAsync(sUri);
                    Console.WriteLine(sUri);
                    response.EnsureSuccessStatusCode();
                    string responseBody = await response.Content.ReadAsStringAsync();
                    Console.WriteLine(responseBody);
                    jResult = JsonConvert.DeserializeObject<JSONGoogleAPI>(responseBody);
                }
                catch (HttpRequestException e)
                {
                    Console.WriteLine(e.Message);
                }

Kindly leave a comment if you have any questions.

Cheers

Calling Google Place APIs from Javascript codes

Hi,

Today I’m going to share on how to call Google APIs from Javascript codes. Note that as prerequisite you need to have Google API key that you can obtain from Google Cloud Platform website. You need to however provide a payment method (i.e. provide your credit card information) for billing. Note that these APIs calls are not free, so be careful when using it, especially if it’s using programming loop which may call the API inconsiderably many times.

Add a Div in HTML file

  • <div id=”mymap_id”></div>

Add reference to Google APIs javascript codes

Instantiate Google Service object

  • const map = document.getElementById(“mymap_id”);
  • const service = new google.maps.places.PlacesService(map);

Call the Google API using the object

Example below call nearbySearch API

  • service.nearbySearch(request, callback);
    • request is the parameter defined as below (as example)
      • const request = {
      • location: new google.maps.LatLng(-6.3068678,106.6966153),
      • radius: 10000,
      • opennow: false,
      • keyword: “chinesse”,
      • type: “restaurant”
      • };
    • callback is a function which will be called when we got a response from Google API
      • function callback (response, status, pagination)

Please let me know if you need more information by leaving a comment.

Cheers

Installing SSL Certificate in IIS

Hi,

Today I’d like to share a way to install SSL Certificate in IIS. I use a free SSL certificate, hence need to renew it every 90 days.

SSL for yangdekat.com (free – renew every 90 days)

Create and download a Certificate file

To Download crt, you can use a free for 90 days certificate from https://app.zerossl.com/

Convert to pk12

Refer to: https://help.zerossl.com/hc/en-us/articles/360058296034-Certificate-Format

  • install openSSL from https://slproweb.com/products/Win32OpenSSL.html
  • from command prompt: copy /b certificate.crt + ca_bundle.crt full_chain.crt
  • “C:\Program Files\OpenSSL-Win64\bin\openssl.exe” pkcs12 -export -out certificate.p12 -inkey private.key -in full_chain.crt

Import using IIS

Refer to https://www.thesslstore.com/knowledgebase/ssl-install/microsoft-iis-7-ssl-installation/

  1. Launch IIS Manager
    Click Start, Control Panel, Administrative Tools, and then select Internet Information Services (IIS) Manager.
  2. Select your server name
    In the left Connections menu, select the server name (host) where you want to install the certificate.
  3. Navigate to the Security section
    In the center menu, click the Server Certificates icon under the Security section near the bottom.Microsoft IIS 7 Step4
  4. Click Complete Certificate Request
    In the right Actions menu, click Complete Certificate Request.Microsoft IIS 7 Step5
  5. Browse to your Server Certificate (*.p12)
    In the Complete Certificate Request wizard, click “…” to browse and select Your Server Certificate file that was previously saved on your server’s desktop.
  6. Name your certificate
    Enter a Friendly Name which is an internal reference name to distinguish the file later. We recommend including the CAs name and expiration date.Microsoft IIS 7 Step7
  7. Click OK
    Click OK and the newly installed certificate should appear in the refreshed Server Certificate List.

Bind to IIS site

  1. Access your Sites folder in IIS
    From the left Connections menu, expand your server’s name, expand the Sites folder, and then select the site (e.g. Default Web Site) that you want to secure.
  2. Click Bindings…
    In the right Actions menu, click Bindings…Microsoft IIS 7 Step11
  3. Click Add
    In Site Bindings…, click Add.Microsoft IIS 7 Step12Note: If you already have the appropriate site binding created, click “Edit” and change the SSL Certificate accordingly.
  4. Input the following
    In Add Site Bindings, enter the following information:
    • Type – Select “https”.
    • IP Address – Select “All unassigned”. Now, if you have multiple IP addresses, select the correct one that applies.
    • Port – Enter “443” unless you are listening to SSL traffic on another port (e.g. 992).
    • SSL Certificates – Select the “friendly name” of the SSL certificate you just installed. You can always click “View” to confirm the certificates validity details.
  5. Click OK

Cheers

Configuring IIS for web application accessible from internet

Hi,

Today I’m going to share IIS configuration for my website hosted in my laptop at home that is accessible from internet using HTTPS port 443 using a domain name subscribed from a domain name provider.

Edit Binding for https protocols in port 443 for localhost and domain name

Localhost binding
Domain name binding

SSL Setting

SSL setting

Set Environment Variable

Set environment variable ASPNETCORE_ENVIRONMENT to Development

That’s it.

Cheers

How to host a web server in your PC/laptop at home and make it accessible by public from Internet

  1. Develop your web site
    • I’m using Visual Studio ASP Net Core (MVC/RazorPages) to build a web application hosted in Microsoft Windows IIS (internet Information Service).
    • Other methods that I know:
      • Create a HTML file using simple text editor, may also include javascript
      • Create an PHP app and host it in Apache web server
  2. Publish it to your IIS where the web app is hosted
  3. Configure your IIS where the web app is hosted
  4. Ensure that firewall is opened for the ports you are using (typically port 80 for HTTP or 443 for HTTPS) in the PC/laptop the web app is hosted
  5. Ensure that the PC/laptop hosting your web app is using static IP (not dynamic IP)
  6. Ensure that the PC/laptop hosting your web app is connected to the internet
  7. Test accessing your website from localhost or any other PC/laptop in the same network subnet
  8. Configure your home/local router so that the PC/laptop hosting your web app is in DMZ zone, or you can also use port forwarding
  9. Contact your ISP to get a public IP (subscription)
  10. Access your website from internet using the public IP

Get Your Domain

  1. Subscribe from domain name providers to get your domain name
  2. Configure the CNAME in the domain provider tools to point to your public IP provided by your ISP
  3. Access your website from internet using the public IP

To use SSL for HTTPS

  1. Get a certificate from the SSL provider (subscription/free)
  2. Install the certificate in PC/laptop hosting your web app
  3. Configure IIS to enable SSL for your website

You can contact me if need clarifications.

You can also check out my website hosted in my laptop at home www.yangdekat.com

Cheers

ASPNet Core Web App – Scaffold Identity

Hi,

Today I’m going to share steps on using Identity Scaffolding to a website so it can use login functionalities.

Note: Identity in ASP.Net is developed using Razor Pages (not MVC)

Step 1

Step 2

Step 3

Step 4

Step 5

Add into Layout.cshtml

MVC: in /Views/Shared/ Layout.cshtml
RazorPage: in /Pages/Shared/_ Layout.cshtml

Step 6

Check appsettings.json for IdentityContextConnection parameter
Ensure DB is up

Step 7

Check the automatically created (scaffolded) Identity DB Context class in /Areas/Identity/Data i.e. RazorPagesMovieIdentityContext

Step 8

Open NuGet PMC (Package Manager Console) in Tools menu

Type:

Add-Migration CreateIdentitySchema –Context RazorPagesMovieIdentityContext

Step 9

Check the automatically created migration class under /Migrations/(Identity DB Conext class name)

Step 10:

Open NuGet PMC (Package Manager Console) in Tools menu

Type:

Update-Database -Context RazorPagesMovieIdentityContext

Step 11

Check Database for created DB Schema

Step 12

Since Identity is developed using Razor Pages (not MVC), Check in Startup.cs

Done.

Additional Notes:

To remove previous migration:

Remove-Migration -Context RazorPagesMovieIdentityContext

Update the model if necessary

And then create a new migration

Cheers

Movies Database – Sample of RazorPage Web Programming

Hi,

Today I’m going to share the logic of simple Web programming using a database. The sample is from Microsoft website, it’s built based on RazorPage concept. I’m just giving the visualization of how it works generally.

RazorPage Movies Homepage

RazorPageMovies Concept

PageModels (1/4)

Pages/Movies/Index RazorPage

Pages/Movies/Create RazorPage

Page Models (2/4)

Pages/Movies/Edit RazorPage

Page Models (3/4)

Pages/Movies/Details RazorPage

Page Models (4/4)

Pages/Movies/Delete RazorPage

I hope you get the idea of simple Web programming using RazorPage and a database by visualization above.

I have also uploaded the Visual Studio source code in this link

Cheers

Movies Database – Sample of MVC Web Programming

Hi,

Today I’m going to share the logic of simple Web programming using a database. The sample is from Microsoft website, it’s built based on MVC concept. I’m just giving the visualization of how it works generally.

Movies Homepage
Movies App Concept

Movies Controller (1/4)

Movies Index View

Movies Create View

Movies Controller (2/4)

Movies Edit View

Movies Controller (3/4)

Movies Details View

Movies Controller (4/4)

Movies Delete View

I hope you get the idea of simple Web programming using MVC and database by visualization above.

I have also uploaded the Visual Studio source code in this link

Cheers

ASPNet Core Web App – RazorPages Concept

Hi,

To, I’m going to share about Razor Page concept in Web Programming

Razor Page Concept (1/3)

Diagram below describes the concept of Razor Page. You can see the relations between Data Model, Razor Page, and Page Model. Razor Page is similar to View in MVC (Model, View, Controller) concept, and Page Model is similar to Controller in MVC concept.

Razor Page Concept 1/3

Razor Page Concept (2/3)

Diagram below shows the steps of creating Razor Page application using scaffold process. You just need to define data model (Model) and let the scaffold process to automatically create a related Page Model and related CRUD (Create, Read, Update and Delete) Razor Page / Razor Views based on the data Model you created. Data Migration process allows creation of database related tables automatically.

Razor Page Concept 2/3

Razor Page Concept (3/3)

Diagram below shows a more detail relationships between Razor Page (Data Model, Razor Page / Razor View and Page Model), as well as DBContext and Migration classes. It also describes the project files within Visual Studio solution.

Razor Page Concept 3/3

I hope above visualization of Razor Page concept can help you understand the basic of Razor Page concept.

Cheers

ASPNet Core Web App – MVC Concept

Hi,

It’s been a while since I wrote my last blog. Now I have got the time, I’m going to share about MVC (Model, View, Controller) concept in Web Programming.

MVC Concept (1/3)

Diagram below describes the concept of MVC. You can see the relations between Model, View and Controller (abbreviated to MVC)

MVC Concept 1/3

MVC Concept (2/3)

Diagram below shows the steps of creating MVC application using scaffold process. You just need to define data model (Model) and let the scaffold process to automatically create a related Controller and related CRUD (Create, Read, Update and Delete) Views based on the Model you created. Data Migration process allows creation of database related tables automatically.

MVC Concept 2/3

MVC Concept (3/3)

Diagram below shows a more detail relationships between MVC (Model, View and Controller), as well as DBContext and Migration classes. It also describes the project files within Visual Studio solution.

MVC Concept 3/3

I hope above visualization of MVC concept can help you understand the basic of MVC concept.

Cheers