February 25, 2020

Deploy your web app!

aspnetcore

You are developing an amazing ASP.NET Core web app and need to give it a house online.  If you anticipate your program you can use an economical Windows Server, IIS hosting provider like SmarterASP.NET.  Of course, alternatively, you could publish your site to a minimal cost Linux VPS hosting service, like Linode, but which may cost somewhat more and configuring the machine will be quite somewhat more work.

These are the steps we will follow to release an asp.net hosting uk web app:

Make an account

Set up a database

Train your app for production

  1. Create an account on the agency that is hosting 

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

The free accounts takes a phone number for an SMS confirmation code.

For 60 days free, they allegedly ask that you post to Facebook and Google+.

Though, I did not do and I still got 60 days !

Here Are a Few Tips when making your account:

You can give your website a title other than site1, I named mine residence.

Select ASP.NET since the account type

asp.net hosting uk

Evaluation the accounts by going to the URL for the temporary domain .  As an example:

Http://yourname-001-site1.htempurl.com/ (not a real URL).  You should see a page.

  1. Create a Database

From the Smarter ASP.NET control panel, then make a MSSQL database

I picked MSSQL 2016.

I called it the same as my web site–only so it would be simple to remember.

Example database name and information:

DB_A452B1_home

Username: DB_A452B1_home_admin

Access the connection string by clicking on”Connection String Examples” at the bottom of the database in the control panel

Choose an ASP.NET link string.  Mine looks like this:

Assess the database with these tools:

Visual Studio’s Server Explorer

DBeaver, a helpful cross-platform free, open-source database manager.

 Prepare the Web App

There are two ways you can set up your app2:

Framework-dependent deployment

The .Net Core run-time package is installed on the server and so that your program utilizes the run-time environment that is already there.

Self-contained deployment

 NET Core bundle is set up alongside your app.

We’re likely to utilize the self-contained approach because it can be complicated to try to change the build settings of your job in Visual Studio so that it is targeting among the variations of. NET Core that is set up on the agency’s servers.  Because of that there is not much to do except to configure the database connection string for the Manufacturing server

Configuring the Manufacturing link string

Insert two new appsettings documents into your project:

appsettings.development.json

Move the connection strings to your community machine to this file.

appsettings.production.json

Set the link string for the database .  Put xxxx or some set up of the password.  Be sure the connection string has 

Example:

“ConnectionStrings”: 

Initial Catalog=DB_A451DA_BookInfo2;User

Place a copy of the identical manufacturing connection string in your default appsettings.json.  This is just to ensure the Visual Studio Publish wizard may see it.

Establish the local machine’s ASPCORENET_ENVIRONMENT environment variable to Development.  The environment variable on the machine will have been set to Production.  

Note: The Visual Studio Publish tool won’t recognize link strings unless they’re in a top-level JSON item called”ConnectionStrings”.

When you are running your program in your development server, the default appsettings.json and appsettings.development.json will be read.  Whenever your program runs on the production machine, appsettings.json and appsettings.production.json is going to be utilized.

  1. Deploy the Internet Program 

There Are Lots of Distinct methods you can use to deploy your app with the Visual Studio Publish wizard:

WebDeploy

This is a proprietary Microsoft protocol for uploading files to a server.  It’s encouraged by SmarterASP.NET and is a great option.

FTP

This, clearly, is a supported protocol and can be another good option.

This choice only places the output in a folder of your choice on your machine.  From there you can manually copy the files.

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

The Basic account on SmarterASP.NET doesn’t support WebDeploy (even though the free trial does).

Some ISPs or company firewalls block WebDeploy.

(At the school where I teach, the network firewall blocks both WebDeploy and FTP.)

 Sometimes it states when actually it has not, it uploaded the files.

  1. Produce a publish profile

Here are the steps to make a print profile for your program:

Start by right-clicking in your job name in the Visual Studio Solution Explorer and selecting Publish.

Click on Configure and from the connection dialog box choose File System as the publish method and enter the place in which you wish to place the output (your location does not need to be just like mine).

Select Settings and enter preferences similar to those from the image below.  Here are some things that may be distinct:

Target Framework–yours might be different.  This will be placed depending upon the target in your Visual Studio project

Databases, connection strings–the connection string names will come from your job and will probably be different from mine.  Your link strings will certainly be different! Make certain to enter the password. I intentionally left mine because xxxxxx for the screen-shot.

Entity Frame Migrations–Duplicate the connection string from Databases, with all the password, and put it all here.  When you run the Publish wizard it will connect to your internet database and then apply the migration. This is equivalent to running ef database update on your local machine.

Make sure your connection string comprises the complete URL for your internet database, such as: SQL5004.site4now.net

Publish-File-Settings.png

  1. Publish the program 

Click Savethen click on Publish and your program will be released to the folder that your chose.

Today you will need to copy the files to your online server.  You can do this with one of two ways:

Use the File Manager that is a portion of this SmarterASP.NET control panel.

On the community machine, zip all files from the folder in which you published your website.  Simply zip the files, not the folder.

In the SmarterASP.NET file manager:

Publish the zip file into your home folder.

Unzip the files.

  1. Run your own app!

 Keep Your Web Program”Alive”

You may observe that in the event you do not access your site for some time (half a day), it will act like it has become dormant and it’ll take a minute or longer to respond when you attempt to open it in a browser.  Listed below are two answers to that problem:

From the SmarterASP.NET control panel, go into the”Advance” settings page and search for”Schedule Tasks”, on this page, input the URL of your web site as a task and set it to run every 20 minutes.

Troubleshooting

Fundamental troubleshooting

Should you see an error page rather than your home page, then here are some items to check:

Can your database tables become created from the Visual Studio Publish magician?  You can check this by using the SmarterASP.NET database viewer to determine whether your database gets the right tables.

If the tables weren’t created, you can check the link string from the print wizard (make sure it has a password) and try publishing again.

 If that’s the case, you could upload your regional database into SmarterASP.NET.  To do this, in the database management panel, pick attach database file.

Can 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.

Can appsettings.production.json contain the correct connection string and password?  This file must have been upgraded by the print wizard. You are able to test it’s contents using the File Manager in the SmarterASP.NET management panel to get this, or install it using an FTP client.

This file is needed to configure IIS to run an ASP.NET Core web site.  The Publish wizard generated the file.

Advanced troubleshooting

You can do additional troubleshooting by enabling error logging in your ASP.NET Core web app.  You Have to do this:

Edit web.config to put stdoutLogEnabled to accurate, for example this:

Guarantee that the folder containing your website has read/write permissions.  (IIS will produce a record sub-folder there.)

Now, turn off your site off and turn it back on and refresh your house page on your browser.  Check the logs folder and see whether there is presently a log file there. When there is, then download it and see what type of clues are inside.