Publishing an ASP.NET Core Web App to a Low-cost Windows Hosting Service

February 18, 2019 at 5:05 pm Leave a comment


You’re developing an awesome ASP.NET Core app and now you need to give it a home on the internet. If you expect your app to experience a light or medium traffic load1, you can use an inexpensive shared Windows IIS hosting provider like SmarterASP.NET. Of course, you could publish your site to an low cost Linux VPS, like Linode, but that is going to cost a bit more and configuring the server will be quite a bit more work.

These are the steps we’ll follow to publish an ASP.NET Core web app:

  1. Create an account
  2. Set up a database
  3. Prepare your app for production
  4. Deploy your web app!

1. Create an account on the hosting service

Smarter ASP.NET offers a free 60 day account without a credit card. There are a couple of caveats though:

  • The free account requires a phone number for an SMS verification code.
  • 60 days free (instead of 30) supposedly requires posting to Facebook and Google+.
    Although, I didn’t and I still got 60 days!

Here are some tips when creating your account:

  • You can give your database a name other than site1, I named mine home.
  • Select ASP.NET as the account type
  • Test the account by going to the URL for the temporary domain name. For example: You should see a page showing the default document.

2. Create a Database

  1. In the Smarter ASP.NET control panel, create a MSSQL database
    • I chose MSSQL 2016, but it probably doesn’t matter which version you use.
    • I named it the same as my web site–just so it would be easy to remember.
    • Example database name and info:
      Username: DB_A452B1_home_admin
  2. Get the connection string by clicking on “Connection String Examples” at the bottom of the database page in the control panel
    • Choose ASP.NET connection string. Mine looks like this:
      “Data;Initial Catalog=DB_A452B1_home;User Id=DB_A452B1_home_admin;Password=YOUR_DB_PASSWORD;”
  3. Check the database using one of these tools:
    • The online database manager: Webbase MS SQL Server Manager
    • Microsoft SQL Server Management Studio
    • Visual Studio’s Server Explorer
    • DBeaver, a useful cross-platform free, open-source database manager.

3. Prepare the Web App

There are two ways you can deploy your app2:

  • Framework-dependent deployment
    The .Net Core run-time package is installed on the server and so your app uses the run-time environment that is already there.
  • Self-contained deployment
    The .NET Core run-time package is deployed along with your app.

We are going to use the self-contained approach since it can be tricky to try to change the build settings of your project in Visual Studio so that it is targeting one of the versions of .NET Core that is installed on the hosting service’s servers. Because of that there isn’t much to do  in this step except to configure the database connection string for the production server

Configuring the production connection string

  • Add two new appsettings files to your project:
    • appsettings.development.json
      Move the connection strings for your local machine to this file.
    • appsettings.production.json
      • Put the connection string for the hosted database here. Put xxxx or some other place-holder in place of the password. Be sure the connection string has the same name as one that is loaded in the Startup class
      • Example:
        "ConnectionStrings": {
        "MsSqlConnection": "Data Source=SQL5004,1433;
        Initial Catalog=DB_A451DA_BookInfo2;User
      • Put a copy of the same production connection string in your default appsettings.json. This is only so that the Visual Studio Publish wizard will see them.
  • Set your local machine’s ASPCORENET_ENVIRONMENT environment variable to Development. The environment variable on the production server will have already been set to Production. For instructions for setting environment variables, see Set the Environment.
  • Note: The Visual Studio Publish tool won’t recognize connection strings unless they are in a top-level object named “ConnectionStrings”.

When you are running your app on your development machine, the default appsettings.json and appsettings.development.json will be read. When your app runs on the production machine, appsettings.json and appsettings.production.json will be used.

4. Deploy the Web App

There are several different methods you can use to deploy your app using the Visual Studio Publish wizard:

  • WebDeploy
    This is a proprietary Microsoft protocol for uploading files to a server. It’s supported by SmarterASP.NET and is a good option.
  • FTP
    This, of course, is a universally supported protocol and is another good option.
  • File System
    This option simply puts the output files in a folder of your choice on your machine. From there you can manually copy the files to the server.

We will use the File System option. The reasons for this are:

  • The Basic account on SmarterASP.NET doesn’t support WebDeploy (although the free trial does).
  • Some ISPs block WebDeploy
  • The FTP option in Visual Studio 2017 appears to be buggy! Sometimes it says it uploaded the files successfully when actually it hasn’t.

A. Create a publish profile

Here are the steps to create a publish profile for your app:

  1. Start by right-clicking on your project name in the Visual Studio Solution Explorer and selecting Publish.
  2. Click on Configure and in the connection dialog box select File System as the publish method and enter the location where you want to put the output files (your location doesn’t need to be the same as mine).


  1. Select Settings and enter settings similar to those in the image below. Here are some things that may be different:
    • Target Framework–yours may be different. This will be set automatically depending on the target in your Visual Studio project
    • Databases, connection strings–the connection string names will come from your project and will likely be different from mine. Your connection strings will certainly be different! Be sure to enter the password. I intentionally left mine as xxxxxx for the screen-shot.
    • Entity Framework Migrations–Copy the connection string from Databases, with the password, and put it here. When you run the Publish wizard it will connect to your online database and apply the latest migration. This is equivalent to running dotnet ef database update on your local machine.
      • Be sure your connection string contains the full URL for your online database, for example:


B. Publish the app

  1. Click Save, then click on Publish and your app will be published to the folder your chose.
  2. Now you need to copy the files to your online server. You can do that using one of two ways:
    • Use the File Manager that is part of the SmarterASP.NET control panel.
      • On your local machine, zip all the files in the folder where you  published your site. Just zip the files, not the enclosing folder.
      • In the SmarterASP.NET file manager:
        • Upload the zip file to your home folder.
        • Unzip the files.
    • Use an FTP client like FileZilla to upload the files

C. Run your app!

Point your browser at the URL for your site and you should see your home page!


Basic troubleshooting

If you see an error page instead of your home page, here are some things to check:

  • Did your database tables get created by the Visual Studio Publish wizard?
    You can check this by using the SmarterASP.NET database viewer to see if your database  has the right tables.

    • If the tables weren’t created, you can check the connection string in the publish wizard (make sure it has a password) and try publishing again.
    • Some ISPs block the database connection. If that is the case, you can upload your local database to SmarterASP.NET. To do this, in the database control panel, select attach database file.
  • Did appsettings.production.json get uploaded to the home folder of your web site?You can check this using the File manager in the SmarterASP.NET Control panel.
  • Does ppsettings.production.json contain the correct connection string and database password?
    This file should have been updated by the publish wizard. You can check it’s contents by using the File Manager in the SmarterASP.NET control panel to download it, or download it using an FTP client.
  • Did web.config get uploaded to the home folder of your web site?
    This file is required to configure IIS to run an ASP.NET Core web site. The file was generated by the Publish wizard.

Advanced troubleshooting

You can do further troubleshooting by enabling error logging from your ASP.NET Core web app. You do this by:

  • Editing web.config to set stdoutLogEnabled to true:
  • Creating a logs sub-folder in your home folder on SmarterASP.NET.

Now, turn off your site and turn it back on and refresh your home page in your browser. Check the logs folder and see if there is now a log file there. If there is, download it and see what kind of clues are in it.


1I’ve done load testing using JMeter on one of my sites on SmarterASP.NET. I ran a test with 100 simulated concurrent users and got an average latency of 50ms and an average through put of 78 pages per second. This is surprisingly good performance for a $2.95 a month plan, and was probably due to using the free CloudFlare CDN provided by SmarterASP.NET.


1For more information on different ways to deploy ASP.NET Core web apps, refer to this article in the Microsoft Documentation: Deploy .NET Core apps with Visual Studio

Entry filed under: .NET, Programming. Tags: , , , .

ASP.NET Core Razor Pages – Part 1

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

Bird’s Bits

Computers, software & the Internet

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 39 other followers

%d bloggers like this: