Asp.Net MVC Publish with Web Deploy

We will learn how to publish/deploy mvc web application to IIS server using web deploy in visual studio or use web deploy option in visual studio to deploy/publish mvc web application in server with example.

Publish Site using Web Deploy in Visual Studio

In visual studio 2012, we have One-Click publish options. Using those options, we can deploy/publish mvc web application to IIS server directly from visual studio. We have different types of publishing options available in visual studio 2012 in that one option is Web Deploy.


Here we will learn the step-by-step process to deploy or publish mvc web application using the Web Deploy option in visual studio. To publish and deploy applications here, we will use a simple Internet Application that we already created for deployment with the name [OrderApp] like as shown below. mvc sample application to deploy / publish using visual studio


Now let’s build this application and run. Following is the snapshot after running the application. mvc web deploy application output


It is working fine. Now we have checked our application, and it's working fine. Let’s publish this Application; before starting to publish our Application, Run Visual Studio as Administrator like as shown below.


Run Visual Studio As Administrator to Publish / Deploy Application

Publishing Application using Visual Studio

To publish an application, right-click on Project name [OrderApp], and a list of options will appear from that List select [Publish] options like as shown below.


Right click project and select publish option to deploy application


After selecting the Publish option, a new dialog will pop up with the name Publish Web as shown below.


Publish web deploy dialog to deploy mvc web application


In this dialog, it will first ask you to create a profile. If you have created a profile already, you can select a profile from the Manage profile. Just click on the Manage Profile button a new small dialog box of Edit Web Publish Profiles will appear to see your already created Profile.


Created Web Publish Profiles in Visual Studio Deployment


If you had proper look at the Publish Web dialog box, you would also find the Import button. After clicking on the Import button below, a dialog will appear in this dialog you can import from Azure Website or from Publish profile file.


Import profile from windows azure website or from publish profile file


We are new to publish this application; hence we are going to create a New Profile.

Creating New Profile (stage 1)

To create a New Profile, select the [Select or Import a publish profile] dropdown after selecting a [New Profile] item will appear in the dropdown list just select that.


Select New Profile from from Select or Import a Publish


After selecting a New Profile, a new dialog box will appear with the name [New Profile] asking to enter a Profile name.


Enter Profile Name to Create in Publish Web Dialog


Here we entered the profile name as [OrderAppDeploy]. You can enter the profile name of your choice.


Entered Profile Name as OrderAppDeploy to Publish Application


After entering the profile name, click on the OK button. This process will move forward to the next stage, the Connection setting.

Connection setting in Visual Studio (Stage 2)

Now we will select a way to publish our application for that. We need to move to the second step connection like as shown below.


Select publish method to deploy application in visual studio


If we click on the Publish method dropdown, we can see the list of ways to publish an application. For details, you can have a look at the below snapshot that shows Publish method Items. From this option, we are first going to choose the Web Deploy option.


Select Web Deploy Options from Publish method in Visual Studio


Here we selected the Web Deploy method. We need to provide the Server name, Site name, Destination URL. If we enter all Publish settings, this site will be deployed on the server to enter details.


Here we are going to deploy the application in the local IIS server. For that, we need to enter details like as shown below.


  • Server name - localhost
  •  Site name - Default Web Site/OrderApp 
  •  Destination URL - http://localhost/OrderAPP 

Once we enter all the server details, we want to deploy the application that will be like as shown below.


Enter All Server Details to Publish Web Application in Web Deploy


After entering all the details to deploy applications, click on the Next button to Move Forward to the next stage of the deployment process.

Settings for Deploying Application (Stage 3)

In this process, it will ask for selecting Configuration; we have 2 options for this


  1. Debug - Debug is used for debugging.
  2. Release Mode - Release is the final deployment.

Here we are going to select Release mode.


File Publish options section


After Selecting Configuration, we have File Publish options those like as shown below.


  • If we want to remove additional files at the destination, then we need to select this option.
  • If we want to Precompile the application during publishing, then we need to select this option.
  • If we want to exclude files from the App_Data folder, then we need to select this option.

Here we selected 2 options of [File Publish options] that will be like as shown below.


Select File Publish Options in Publish Web Dialog to Deploy Website

Configuring Database section

If we have a remote connection string, we need to configure from here to select the browse button to set the remote Connection string. After choosing this option, we need to enter all the details of SQL Server with Server name, Username, and Password. Following is the snapshot, which we entered all the details.


Configure Database Remote Connection to Publish Web Application


After completion of adding all database setting now click on the OK button. Following is the snapshot after configuring the database connection.


After configuring database connection string in publish web dialog


After entering all details related to the destination, Connection String Click on the Next button to Move Forward to the next stage of the deployment process.

Preview Details (Stage 4)

In this preview section, we get a chance to view the files of our application going to Publish. Here we have checked and unchecked files option, which will help us remove (uncheck) files that we don’t want to publish.


It will preview all the files in the first deploy, and on the next deploy, only the changes will be Previewed. Following is the snapshot of the Preview dialog window.


Preview Files which we are going to publish using visual studio


After reviewing all the files finally click on the Publish button. Once we click on the publish button, publishing will get a start, and the site will get publish on the IIS server inside Default Web Site. Following is the snapshot of the site getting publish.


Publishing website using web deploy in visual studio


Now to see where IIS is located for new people to development or deployment, enter Windows + R from the keyboard. A new Run window will Pop up inside that type text inetmgr, and press enter a new window should pop up of Internet Information Services (IIS) Manager. 


Now we can see the site [OrderApp] is deployed to IIS inside Default Web Site that will be like as shown below.


Publish / Deployed App in IIS using Web Deploy in Visual Studio


If you observe, our deployed application already started running so we can access the application. Here there is a chance of getting error 503 like as shown below.


Service Unavailable HTTP Error 503 After Publishing Website


To solve this Error 503, we need to change the app pool of deployed applications.

Error 503 Resolving in IIS

To Resolve Error, you need to go to IIS Manager à then select your Application à then in the right side you will see Actions panel inside that select [Basic setting…] a new dialog will pop up with name Edit application like as shown below


Edit Application Pool in IIS for Web Deploy


After that click on the select button, a new dialog box will popup to select Application Pool in this select ASP.NET V4.0 or any other Application Pool but .Net Framework Version must 4.0.


Select Application Pool v4.0 in IIS to Solve Error


After setting Application Pool, you can check Site it will be Live.


After Deply and Change Application in IIS Result of Deployed Asp.Net MVC Website


This is how we can Web Deploy method in visual studio to deploy a web application in IIS Server.