We will be deploying (publishing) a web app to a production server running the Windows Server operating system and using IIS (Internet Information Server) as a web server. This example uses a commercial shared
These are the steps to publish an ASP.NET Core web app to Smarter ASP.NET
- Create an account
- Set up a database
- Prepare your app for production
- Publish your web app
1. Create an Account
Smarter ASP.NET offers a free 60 day account without a credit card.
- 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!
- 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:
2. Create a Database
- In the 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:
- 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:
- Check the database using one of these tools:
- The online database manager:
Webbase MS SQL Server Manager
- Microsoft SQL Server Management Studio
- Visual Studio Server Explorer
- DBeaver, a useful cross-platform free, open-source database manager.
3. Prepare the Web App
- Use the User
Secret Manager to hide the password in the production database connection string.
Configure a production connection string
- Right-click on the project, select Manage User Secrets. This adds the following section to the .csproj file:
. . .
- Add a new file to your project named appsettings.production.json
- In this file add a section for connection strings and add the connection string for your production database. Be sure the
connection string has the same name as one that is loaded in
- 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
- Note: The Visual Studio Publish tool won't recognize connection strings unless they are in a top-level object named "ConnectionStrings".
If you will be doing a Framework Dependent installation, set the target framework in your Visual Studio project for one that is supported by the production server.
- The production server may not support the latest version of ASP.NET Core. For example, the latest version that Smarter ASP.NET currently supports is 2.0.0.
- You need to find a version for which you have an SDK installed on your development machine and which is supported on production server. In my case, using Smarter ASP.NET, that was version 2.1.2.
- Set the target framework in the build properties of your project to 2.1.2
- Set the target framework in the Publish dialog to 2.1.2 as well.
When you are running your app on your development machine, only the default appsettings file, appsettings.json, will be read. When your app runs on the production machine, both the default appsettings and the production appsettings files will
4. Deploy the Web App
Create a publish profile in VS 2017
Follow the instructions in the knowledge base article, How
to publish ASP.NET Core web application via Visual Studio 2017.
- Connection page:
- Warning! For Server URL, don't use the control panel's "Show Web Deploy Info", Service URL. Use the one from the knowledge base article that looks like this:
Replace the highlighted sections with your own details
- Test the connection using the Validate Connection button
When the connection succeeds, you will get a warning about the security certificate.
Check the checkbox to have Visual Studio remember the certificate and accept
- Settings page:
- Choose the options shown in the knowledge base article instructions
- Decide which kind of deployment you want make:
- Framework dependent deployment
Your app will use the DotNet Core runtime on the host machine. You will need to make sure your app is compiled to the right version of the SDK for the machine's runtime.
- Self-contained deployment.
Your app will be bundled with it's own run-time. This will require more resources (primarily memory), but you can use any version of DotNet Core you wish.
- Use the connection string you got from the control panel in the previous section, don't include the quotes, and replace YOUR_DB_PASSWORD with your own password, like this:
Publish the Web App!
- Click the publish button to publish the files to your web site!
- Open the site page to see your web app. For example:
Here are my raw troubleshooting
Q: Is there a way to tell what settings were used for publishing a site by looking at the published binaries?
A: Yes, for some things:
- Deployment Mode:
- Web.config contains an aspNetCore element with arguments set to the app's executable:
<aspNetCore processPath="dotnet" arguments=".\BookInfo.exe"
stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
- In version 2.1 there is a Views folder, but not in 2.2
- Web.config contains an aspNetCore element with arguments set to the app's dll:
<aspNetCore processPath="dotnet" arguments=".\BookInfo.dll"
stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
- Target Runtime = Portable if there is a runtimes folder
Q: If my database has empty tables, how do I get seed data into the tables?
A: If your seed data method is called from the Startup file, then you just need to turn off your web site and turn it back on.
Q: If my firewall is blocking Visual Studio from running the migrations SQL script when I publish my web app, is there another way to create the tables in my database?
A: Yes, you can use the attach .mdf file option in the database page
of the SmarterASP.NET control panel to upload the database file from your local machine.