Here 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 by using those options we can deploy / publish asp.net mvc web application to iis or server directly from visual studio. We have different type of publish options available in visual studio 2012 in that one of option is Web Deploy.
Here we will learn step by step process to deploy or publish asp.net mvc web application using Web Deploy option in visual studio. To publish and deploy application here we are going to use simple Internet Application which we already created for deployment with name [OrderApp] like as shown below.
Now let’s build this application and run. Following is the snapshot after running application.
It is working fine. Now we have checked our application and its working fine now let’s publish this Application. Before starting to publish our Application just Run Visual studio as Administrator like as shown below.
To publish application just 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 Publish option a new dialog will pop up with name Publish Web like as shown below.
In this dialog it will first ask you to create a profile. If you have created profile already then you can select profile from Manage profile just click on Manage profile button a new small dialog box of Edit Web Publish Profiles will appear in that you can see your already created Profile.
If you had proper look on Publish Web dialog box you will also find Import button. After clicking on Import button below dialog will appear in this dialog you can Import profile from Azure Website or you can Import 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 just select [Select or Import a publish profile] dropdown after selecting a [New Profile] item will appear in dropdown list just select that.
After selecting a New Profile, a new dialog box will appear with name [New Profile] asking to enter Profile name.
Here we entered profile name as [OrderAppDeploy] you can enter profile name of your choice.
After entering profile name just click on OK button then this process will move forward to next stage Connection setting.
Now we are going to select a way to publish our application for that we need to move to second step connection like as shown below
If we click on Publish method dropdown we can able to see the list of ways to publish an application. For details you can have a look on below snapshot which shows Publish method Items. From this option we are first going to choose Web Deploy option.
Here we selected Web Deploy method then we need to provide Server name, Site name, Destination URL. If we enter all Publish settings, then this site will get deployed on the server which we entered details.
Here we are going to deploy application in 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 details of server we want to deploy the application that will be like as shown below
After entering all the details to deploy application then click on Next button to Move Forward to next stage of 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 remote connection string, then we need to configure from here for that just select browse button to set 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 OK button. Following is the snapshot after configuring database connection.
After entering all details related to destination Connection String Click on Next button to Move Forward to next stage of deployment process.
In this preview section we get a chance to view what are the files of our application which are going to Publish. Here we have check and uncheck files option which will help us to remove (uncheck) files which we don’t want to publish.
In first deploy it will Preview all the files and on next deploy only the changes will be Previewed. Following is the snapshot of Preview dialog window.
After previewing all the files finally click on Publish button once we click on publish button publishing will get start and site will get publish in IIS server inside Default Web Site. Following is the snapshot of site getting publish.
Now to see where IIS located for people who are new to development or deployment just enter Windows + R from keyboard a new Run window will Pop up inside that type text inetmgr then 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 application. Here there is a chance of getting error 503 like as shown below
To solve this Error 503 we need to change app pool of deployed application.
To Resolve Error, you need go to IIS Manager à then select your Application à then in 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 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 now you can check Site it will be Live.
This is how we can Web Deploy method in visual studio to deploy web application in IIS / Server.