6 Steps to host ASP.NET MVC/Core application on server

Posted by in IIS category on for Advance level | Points: 250 | Views : 14402 red flag
Rating: 5 out of 5  
 1 vote(s)

This article explains every step to follow in order to host an ASP.NET application. This application can be ASP.NET MVC or ASP.NET Core.
Read How to host asp.net application on the web server (IIS) before this article.


We as a developer know how to develop an ASP.NET application (MVC/Core) however when it comes to hosting, we do not understand how the dns server and name server etc works and what steps to follow to host an asp.net application.

In this article, we shall try to explain each step in hosting an asp.net application successfully.

Step 1 - Domain booking and changing Nameservers

If you have not already booked your domain name, you can go here (i trust) and book your domain along with hosting.
The most important part of hosting an application is to target the domain name to our application server where we have uploaded our files.

To target your domain to the hosting server, you need Nameservers. Every hosting provider gives you two nameservers, it is a must that helps you to configure in your domain name system. If you have not received your Nameservers yet, see your domain provider control panel or contact their support system.

Nameservers looks like xxx.domain.com where
  • xxx - is the prefix (unique to your domain), you can keep your own server name if your server is dedicated or vps.
  • domain - is the primary name of your domain
  • .com - is the extension name of your domain
Most of the hosting provider gives two Nameservers and you will need to update it to your domain as shown below (screenshot of godaddy panel).

Once the Nameservers are updated for the domain, it may take few minutes to point the domain name to your hosting server, so browse your domain in the browser to ensure that it is pointing to right server. Instead you can also go to window command prompt and use ping with domain name as shown in the picture below.

If the IP address showns as ping result is your server hosting IP address, you are good to go.

Step 2 - Creating a website in IIS & ftp on your hosting server

There can be two scenarios here.
  1. Shared hosting - If you or client has bought a shared hosting, you do not need to worry. Your hosting provider would do your work of creating a website on their IIS server and will give you ftp details to upload files, setup right version of iss etc. In this case, you should are always dependent on your service provider if something goes wrong while hosting.
  2. VPS or Dedicated server - There can be two scenarios here
    • Fully Managed - If your server is fully managed, your server provider should take care of creating websites and setting up IIS and other things for you.
    • Not fully managed - In this case you are on your own and you will have to create, configure everything yourself

      In both cases, you must have got a web based control panel like cpanel or websitepanel from hosting server provider that let you create a website and ftp by logging into your control panel. If you have not got yet, it is due; just contact your hosting service provider.

      Login to your control panel and create a website and ftp. This article doesn't explain these details here as every panel has it's own user interface however they are very straight forward. 

      Few server provider sells these web based control panel separately, so ideally you should be it along with hosting as setting up IIS manually is little tough job for a normal developer or software professional.
So log into your control panel and create a website mentioning your domain (this creates a site in your server IIS) and create an ftp targeting to your website (allows your to upload your files and folders).

Step 3 - Creating a database

Once your website and ftp are created, you would certainly need a database unless you have a static website. 

There are two scenarios here

Shared hosting - this has certain limitations on how many database can be created. In your hosting provider control panel you will have option to create a database, so create one.

Dedicated or VPS hosting - this is completely up to you on what database you want to use. If your's is a simple application and assuming few thousand hits a day, SQL Server express would do just fine. As SQL Server Express edition is free and best suitable for ASP.NET application on IIS so you can download it freely from Microsoft website and install it yourself (if not already installed by the hosting provider).

If you are expecting huge visitors base, you may opt for other version of SQL Server that is not free and you will have to buy from Microsoft website.

In case you had chosen to use MySql (again free for non enterprise), do accordingly.

Once the database is created, it's time to migrate your database to the server. 

Creating a database on the server

The best way is to script the database and execute it on the server (Shared hosting would have a Sql Query window similar to Microsoft Management Studio for SQL Server query window).

Or Backup the database and restore it on the server.

Important points to consider
There might be some initial values in few database tables, so ensure that you are either creating insert script for that also and running on the server or manually enter those records into the server database table.

Step 4 - Compiling ASP.NET application / Publishing ASP.NET application

Assuming your ASP.NET application development is complete and you have not compiled and published the application. It's time to compile in Release mode and publish the application.

Do it and you should be getting only .dll, .css, .js, .html, .cshtml and other static files in the published folders. Ideally your server should not go any raw source code (C# class file code).

In some cases ASP.NET Web Form website can also be uploaded on the serer along with the code behind files and it works well however this is not recommended.

Step 5 - Uploading files to the hosting server
Once your domain is pointing to the correct IP address (hosting server) and the database is created; you will need FTP details to to connect to your server in order to upload your files here. In general hosting provider gives you at the time of buying the hosting server, if not please contact your hosting provider.

Once you have the FTP details (host name, username, password), you can use FileZilla (freely downloadable) to connect to the ftp server. Below is the screenshot of FileZilla connect screen.

Enter your domain name in the Host box, username and password into respective boxes and click Connect. You will see a screen something like this. Left side would be your local machine drive, folders and files and right side would be server folders where you will need to upload files.

Alternatively, you can use any browser and write ftp.yourhostname.extensionname (eg. ftp.mydomain.com) in the address bar, enter username and password when prompted and you will be there. Copy-paste the file into respective folder.

Common Misconception: A common misconception is that there would be a wwwroot folder in the server where your files will go but that is not true always. It depends on the server provider to configure the file name where your files will get uploaded.

So from left side window, open the application compiled folder location and double click it to send to the server or right click and select Upload.

This way, your entire published folder should be uploaded to the server.

Step 6 - Setting up IIS

Now it's time to setup your IIS for the correct version of .NET Framework in the application pool. Read this article for basic help.

The most important part of this setup is to create a separate application pool for your website so that it's operation doesn't get affected with the crash non performance of other applications hosted on this IIS. The default application pool is set for the newly created site on the IIS so we need to change it.

Right click the 'Application Pool' node from the left panel of IIS (open iis by writing 'inetmgr' into Run window). Select 'Add Application Pool...'.

This opens up a dialog box that looks similar to below, write the name of the application pool into 1st text box and select the .NET CLR Version. Click OK to create new Application Pool.

To use this application pool for the newly created website, right click the website and select Manage Website > Advance Settings... as shown below.

A dialog box appears, select the Application Pool row and a ... button appears, Click on the ... button against the Application Pool name and you would get following dialog box (Select Application Pool). Select the Application Pool you just created and click OK.

Now, try to browser your application and it should be running well.

Other important points to consider

  1. In the web.config or project.json file, do not forget to set debug mode false.
  2. Change the database connection string to live database into app settings
  3. Do not make the hosted application folder browsable (Set Enable browsing false to the folders where you have uploaded file). In most cases, it is by default false.
  4. Always upload 'Release' mode compiled .dll to the server for the best performance.
  5. Ideally, the database connection strings should be encrypted to avoid misuse or steal
  6. Do not store password into plain text in the database server
  7. Use database connection pooling for best result from the database
  8. Use minified version of JavaScript and CSS files (Read TechFunda articles to know more)
  9. Use CDN for jQuery, AngularJS and other third party open source plugins to increase the performance (Read TechFunda articles to know more)
  10. Always use robots.txt to restrict search engines to not scroll your particular page or folder
  11. Use www.google.com/webmaster (not mandatory) to register your website into google
  12. Use www.Google.com/Analytics (not mandatory) to track the visitors and other details on your website
Hope this article was useful, thanks for reading.
If you are facing any problem while hosting your application, do let me know by responding to this post and I'll try to answer them as soon as I can.
Read Star rating system in ASP.NET MVC after this article.
Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Sheo Narayan
Member Level: HonoraryPlatinum
Member Status: Administrator
Member Since: 7/8/2008 6:32:14 PM
Country: India
Regards, Sheo Narayan http://www.dotnetfunda.com

Ex-Microsoft MVP, Author, Writer, Mentor & architecting applications since year 2001. Connect me on http://www.facebook.com/sheo.narayan | https://twitter.com/sheonarayan | http://www.linkedin.com/in/sheonarayan

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)