We will learn how to publish/deploy asp.net mvc web application to IIS server using web deploy in visual studio or use web deploy option in visual studio to deploy/publish asp.net mvc web application in server with example.
In visual studio 2012, we have One-Click publish options. Using those options, we can deploy/publish asp.net 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 asp.net 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.
Now let’s build this application and run. Following is the snapshot after running the application.
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.
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.
After selecting the Publish option, a new dialog will pop up with the name Publish Web as shown below.
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.
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.
We are new to publish this application; hence we are going to create a New Profile.
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.
After selecting a New Profile, a new dialog box will appear with the name [New Profile] asking to enter a Profile name.
Here we entered the profile name as [OrderAppDeploy]. You can enter the profile name of your choice.
After entering the profile name, click on the OK button. This process will move forward to the next stage, the Connection setting.
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.
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.
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.
Once we enter all the server details, we want to deploy the application that will be like as shown below.
After entering all the details to deploy applications, click on the Next button to Move Forward to the next stage of the deployment process.
In this process, it will ask for selecting Configuration; we have 2 options for this
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.
Here we selected 2 options of [File Publish options] that will be like as shown below.
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.
After completion of adding all database setting now click on the OK button. Following is the snapshot after configuring the database connection.
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.
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.
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.
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.
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.
To solve this Error 503, we need to change the app pool of deployed applications.
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
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.
After setting Application Pool, you can check Site it will be Live.
This is how we can Web Deploy method in visual studio to deploy a web application in IIS Server.