Publishing ASP.NET core to an AWS Lightsail Windows instance

Photo by Andrew Neel on Unsplash

Publishing ASP.NET core to an AWS Lightsail Windows instance

Setup of a web hosting instance

I decided to look into the web hosting landscape for my personal project. This is a lessons learned type article. You will have to visit links for exact steps to some of the problems solved.

This article assumes you know how to:

  • Publish a website from Visual Studio
  • Manually edit XML files
  • Find the location of the .pubxml file of the Publish Profile you are using from Visual Studio
  • Use Windows Disk Management tool to create a drive partition

I have a website with the following specs:

As of today, January 6, 2022, AWS Lightsail is running a special where you can have up to two instances free for 3 months. This was perfect for me to learn what it takes to setup and what it looks like to maintain on an ongoing basis.

Steps after creating a Windows instance

Source

I did not have to follow all the steps in the above article. I did the following

  • Open up ports for Web Deploy
    • In the AWS Lightsail instance, go into the Network tab and add a custom firewall rule to allow port 8172. Web Deploy uses this port.
  • Install IIS
  • *Install .Net Core bundle
    • I had to install the 5.0 bundle here
    • Selecting 5.0 takes you to a screen with MANY links. Find ASP.NET Core Runtime 5.0.13 (as of Jan 6, 2022) and select "Hosting Bundle" link
    • *Internet Explorer is what you have to work with. I felt like gouging out my eye with a spoon. You cannot download anything by default. Add "microsoft.com" to you trusted sites.
      • If I had known about RDC local resources option at this point, it might have saved me some headache. See below.
  • Changed the IIS application pool to "No Managed Code"

If you don't want to manually create you Publish profile

Create a publish settings file from IIS here

No SSL certificate

I do not have an SSL certificate setup as this is for prototyping only. This caused problems with Publish in Visual Studio as it expects a trusted certificate. You will need to manually edit the .pubxml file to include the entry

<AllowUntrustedCertificate>True</AllowUntrustedCertificate>

The example I found here looks like the following:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <UseMSDeployExe>True</UseMSDeployExe>
        <AllowUntrustedCertificate>True</AllowUntrustedCertificate>
...

My .pubxml looks like this after making the change:

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <AllowUntrustedCertificate>True</AllowUntrustedCertificate>
...

How to get files uploaded to the WINDOWS instance

Years ago (don't ask), I used a web host that had PHP website, MySQL on an Unix (don't remember the flavor) server. Filezilla was my friend. The only way to get any change to the web server was to use Filezilla.

I used JetBrains for my PHP development on a LAMP (M was for MySQL) on a Windows development box. It worked great.

I was stuck in that mindset when I turned my attentions on how to copy up my SQLite database. You see, I actually have two websites that will be sharing the same database for login information. I have the path to said database outside of the website file structure and since SQLite is a file based database, I needed to copy said database up to the instance.

Time passes researching how to sFTP up to the Windows instance...all the articles I found when searching on how to connect to AWS Lightsail via sFTP revolved around Linux instances.

Quick answer: Do not use sFTP. Use Remote Desktop Connection(RDC)

Explanation is here.

Scroll to "Transfer files to Windows instances" near the bottom of the post for instructions.

I created another drive that will be dedicated for file transfers. I will be treating this drive as a folder in concept. RDC only maps to the drive level. I don't want my entire drive available to the hosted instance.

Whew...

After all that, using the public IP address, I was able to see my website function.**