How To Deploy ASP.NET MVC 4 Application On Local IIS

First, open your Visual Studio to create an MVC application.

Now, click on File => New => Project => ASP.NET MVC 4 Web Application.

MVC

  • Give a name to your application and click on OK button.
  • Select the Basic template and click OK.

    MVC
  • Now, we have to add a Controller.
  • To add the Controller, go to Solution Explorer and right click on Controllers folder => Add => Controller.
  • Name it as HomeController.

    MVC

    MVC
  • Now, you have created the application.

    MVC

The code given below is used in HomeController.

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Mvc;  
  6.   
  7. namespace MvcSampleApp.Controllers  
  8. {  
  9.     public class HomeController : Controller  
  10.     {  
  11.   
  12.         public ActionResult Index()  
  13.         {  
  14.             return View();  
  15.         }  
  16.   
  17.     }  
  18. }   

Now, let's see the structure of our application.

MVC

  • Now, let's create a View page for Index action method.
  • To create the View, right click on Index Action Method name => Select Add View.

    MVC 
  • Click on Add button.
  • Your View should look like this. You can enhance your functionality but here, I'm showing a simple example which displays Index as an Output.

    MVC

    Code used in my View page i.e Index.html
    1. @{  
    2.     ViewBag.Title = "Index";  
    3. }  
    4. <h2>Index</h2>  
  • Build your project. (Just press F6 to start the build).
  • After the build was successful, we are ready to deploy it.
  • MvcSampleApp is my project name. So, just right click on project in Solution Explorer and select Publish => Publish.

    MVC
  • Click on Custom. It will ask for the profile name. Give the Profile name (It is the name which is given to the host).
  • If you already have the profile name, then click on ManageProfiles and select your profile name.
  • The first time, it will display like the following.
  • Click on Custom.

    MVC

    MVC
  • By default, Publish method will be selected as Web Deploy.
  • Change it by selecting File System.

     MVC
  • Click on Next.
  • We need to provide the Target Location.
  • The target location is the location where our application published code will be generated after publishing.
  • Here, I have created one main folder called "PublishedCode" on D drive.
  • In that folder, I recreated sub folder with my application name i.e. MySampleApp.
  • So, when I am done with publishing all the dll files, my application will be stored in my MySampleApp folder.
  • Now, click on Next.

    MVC 
  • Click On Next again.

    MVC

  • Finally, click on Publish.

    MVC 

When we are successfully done with publishing, we will see this message in the Output.

MVC

  • Go to that location. 
  • Simply copy that location and paste it in Run prompt. 
  • Click OK. 
  • It automatically directs to that location.

    MVC

Go to that location and copy the entire application folder. (It is the folder which contains Published Code).

MVC

Now, we need to start the IIS Manager.

  • For that, you can type IIS in your search box and click OK.
  • Or, you can type inetmgr in run command.
  • In IIS Manager, expand the arrow button showing near localhost, expand the arrow beside sites, and then expand default web site.

    MVC

  • Here, you will find your published code folder of your application. Now, right click on that folder and choose "Convert To Application". It will show a dialogue box. In there, click on OK. 

    MVC

    MVC

Here, you will observe that the published code folder is converted into a website.

MVC


Lastly, right click on that MvcSampleApp and choose "Manage Application" and click on Browse.

Finally, we are done with it. Here is the output after hosting the application on IIS Manager.

MVC

Thank you for reading this article. Happy Coding!!!

Up Next
    Ebook Download
    View all
    Learn
    View all