Since this week, I'm running my websites on a Windows Server 2012. I used to have an Ubuntu Server, but since I'm a .NET developer, a Windows Server is a better choice. I've made a lot of apps for Windows, but never actually deploy a web application to IIS on Windows Server. In this post, I'd like to explain some steps how to deploy your ASP.NET application to IIS.
The method I'm explaining here is fine for deploying simple apps (like blogs or other websites with low user loads), but if you're deploying a mission critical .NET application, you could better set up automatic deployment (which is way out of reach in this post).
- Windows Server (or just a Windows PC with IIS installed)
- Of course, a Windows PC
- Visual Studio (the community edition is free, even for commercial use)
1. Setting Up Your Project
I've just created a basic web project with some default pages. Next, in the project that contains your actual website, go to Properties => Package / Publish Web.
Make sure the option at Items to deploy equals Only files needed to run this application, and save the configuration.
2. Creating a Package
Right click the project that contains your website and click Publish.
Click Custom and fill in a name for the publishing profile (e.g. "Publishing package"). After that, set the Publishing method to Web Deploy Package. Now you can select the location of the package and define a name.
A few files are created, like you can see below. I'm going to copy the file WebApplication1.zip to my Windows Server using Remote Desktop.
3. Creating a Site in IIS
On your Windows Server, open IIS and create a new website by clicking "Add Website" (or something like that, can't check it because my server language is set to Dutch).
Now, fill in the data needed for your website. You have to fill in the name, the location of the website (just create an empty folder for now) and host name of the site (duco.cc and all subdomains of that domain point to my server, so I've test.duco.cc).
4. Copying the Contents of the ZIP File to the Folder
The actual folder in the ZIP file which contains the files for your website, is concealed deep in the file. The folder is called PackageTmp. Copy the contents of this folder to the newly created website folder. Make sure you change the settings in Web.config to match the settings (e.g. the database connection strings) are set appropriately for your server.
If everything went right and you go to the URL of the website you've just deployed, you will see the actual website. Yay!