First, open your Visual Studio to create an MVC application.
Now, click on File => New => Project => ASP.NET MVC 4 Web Application.
- Give a name to your application and click on OK button.
- Select the Basic template and click OK.
- 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.
- Now, you have created the application.
The code given below is used in HomeController.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
-
- namespace MvcSampleApp.Controllers
- {
- public class HomeController : Controller
- {
-
- public ActionResult Index()
- {
- return View();
- }
-
- }
- }
Now, let's see the structure of our application.
- 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.
- 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.
Code used in my View page i.e Index.html
- @{
- ViewBag.Title = "Index";
- }
- <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.
- 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.
- By default, Publish method will be selected as Web Deploy.
- Change it by selecting File System.
- 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.
- Click On Next again.
- Finally, click on Publish.
When we are successfully done with publishing, we will see this message in the Output.
- Go to that location.
- Simply copy that location and paste it in Run prompt.
- Click OK.
- It automatically directs to that location.
Go to that location and copy the entire application folder. (It is the folder which contains Published Code).
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.
- 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.
Here, you will observe that the published code folder is converted into a website.
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.
Thank you for reading this article. Happy Coding!!!