Thursday, September 13, 2018

Entity Framework (EF) Decimal Mapping to SQL Server

We bumped into a strange issue. Value of our property was not saved to the database. We checked mapping, spelling, data type and none seems wrong.

Eventually we found out that the decimal in our database has precision of (12, 6) and the SQL default is (18, 2). Problem is EF map Decimal data type to the SQL default precision thus our value was truncated.

To fix the issue, we put the following code in our DbContext under OnModelCreating method and our value was then saved correctly.

protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
       modelBuilder.Entity<Class>().Property(object => object.property).HasPrecision(12, 6);
}

Autocomplete Bug in Chrome Form Field

I just update my website and everything works great in Firefox. As I test it in Chrome, I noticed when I navigate to another and then press the back button, my text field was populated with wrong data. The data was the default value of other text field before the navigation.

As I was looking around, I found out that it is a bug in WebKit based browsers. Some people suggested to use autocomplete="off" property on all input field. But for my case, it is enough to put the attribute to all text fields (<input type="text"/>).

Saturday, September 8, 2018

A2 Windows Hosting HTTPS Redirect Conflict

With the intention of following best practice, I tried to enforce HTTPS on my websites hosted in A2 Hosting. Under Hosting Settings > Security, I found a check box that says "Permanent SEO-safe 301 redirect from HTTP to HTTPS", it sounds like the right one as it will redirect any HTTP to HTTPS. Because it is a windows server, it also has IIS Settings. And I found "Require SSL/TLS" check box under IIS Settings > Directory Security Settings. That sounds different from permanent redirect, so I check it as well.

When I test the settings by visiting my website using regular HTTP, I received a 403 error. My first attempt to fix the issue was going back to the IIS Settings and set the Authentication from Windows to None. However  that doesn't work. After several trial and error, I have to uncheck the "Require SSL/TLS" check box under IIS Settings > Directory Security Settings to redirect the traffic correctly.

Wednesday, September 5, 2018

A2 Hosting with .NET Core 2.1

Technology advances so fast and I have a new web application which I built using .NET Core 2.1. However, my current web hosting provider does not support .NET Core and I have to look for a new web hosting.

Reading some forums, found out that A2 Hosting plans to install .NET Core 2.1 in their shared hosting on August 2018. So on September 5th, 2018, I signed up for a new account with them. The coupon HOSTINGFACTS that I found from a web hosting review website still works and gave me 53% one-time discount.

Everything went smoothly until I found out that in my Plesk, I was unable to go higher than .NET 4.6.2. So, I decided to chat with their customer support. It took a while to get in touch with an agent, which makes sense because they have lots of customers and it was during busy hour.

From the chat with their customer support, I found out that .NET Core 2.1 has indeed been installed and what is weird is I don't have to flip the .NET version in Plesk. With that information, I decided to try deploy my web application using web deploy mechanism. I had to enable this on the domain level and Plesk will add a link to download the .publishsettings file which can then be imported to Visual Studio.

Deploying my application using web deploy mechanism has a small issue too. A2 Hosting apparently uses self-signed certificate and Visual Studio rejects the deployment because it can't trust it. To workaround it, I found many solutions. One of them is to trust the certificate. However, I don't think it is a good idea to trust untrusted certificate, so I decided to add <AllowUntrustedCertificate>True</AllowUntrustedCertificate> tag on the publish profile xml file.

To add the tag, I can't find the UI in VS2017, so I have to go to my project folder, under Properties > PublishProfiles and manually add it to the .pubxml file.

At last I managed to deploy my application and it worked great. Check it out at: https://www.kodeseek.com :)