Getting Started With IIS Host And Publish In MVC 5

Introduction

This article explains how to host your MVC 5 App in IIS Express and store the data and information in the database created in SQL Server. Visual Studio uses the ASP.NET Development Server as a default and here I am using IIS Server to host a MVC 5 App. As you know, in Visual Studio 2013 Preview the ASP.NET Web Application uses a MVC5 project template and MVC5 uses the Bootstrap theme to display the application, so here I am using the Visual Studio 2013 Preview to develop an application using the MVC project template.

Prerequisites

The following are the prerequisites to develop a MVC 5 application:

  • Visual Studio 2013 Preview
  • SQL Server 2008 or 2012

Creating MVC 5 Application

Let's start to develop an application in MVC 5 using the following procedure.

Step 1

Open Visual Studio 2013 Preview

VisualStudio-in-mvc5.jpg

Step 2: Click on "New Project" and enter the application name.

NewProject-in-MVC5.jpg

Step 3: Select MVC project template to create the project.

MvcTemplate-in-MVC5.jpg

Step 4: In your Solution Explorer, open the Web.Config file.

As you can see, the connection property is available on my file:

  1. <add name="DefaultConnection"connectionString="Data Source (LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MvcIISDemo-20130911053147.mdf;Initial Catalog=aspnet-MvcIISDemo-20130911053147;Integrated Security=True"providerName="System.Data.SqlClient" />  

Now, change the code above as shown below:

Config-in-MVC5.jpg

Step 5: Debug your application and click on the "Register Link" as shown below:

Register-in-MVC5.jpg

Step 6: Enter the details and click on the "Register" button.

Details.jpg

You will see your UserName in your next page window:

HomePage-in-MVC5.jpg

Verify in SQL Server 2012

As you can see, I did not create a database nor any table in my SQL Server 2012. When I declared my connection string, it automatically created a database and table in my SQL Server. You do not need to worry about that.

Let's see my database in my SQL Server Object Explorer.

ObjectExplorer.jpg

Select your database and open the Users Table. You can see the user information as shown below:

UsersTable.jpg

Publish Application

The next step is to host in IIS 8 (IIS Express). For that use the following procedure:

Step 1: In your Solution Explorer select your project and right-click to select Publish.

SolutionExplorer.jpg

Step 2: Select NewProfile and click Next as shown below:

NewProfile-in-Publish.jpg

Step 3: Enter Profile Name and click OK.

Profile-in-publish.jpg

Step 4: Select File System in Publish Method and select your preferred location in the Target Folder.

TargetLocation3-in-publish.jpg

Step 5: Select Release in Configuration in the next window and click "Next".

Release-in-Publish.jpg

Step 6: Click on "Publish" in the next wizard.

Publish-in-Publish.jpg

You will see that the application will publish successfully.

PublishSucceeded.jpg

IIS Host

Open the Internet Information Services (IIS) Manager and follow the procedure given below.

Step 1: Select your Profile in the Default Site.

ConverttoApplication.jpg

Step 2: Just click "OK" in the next Add Application wizard.

AddApp-in-IIS.jpg    

Step 3: Ensure your Default Site Status is Started in Application Pools.

AppPool-in-IIS.jpg

Step 4: Right-click your Profile in the Select Browse in Manage Application.

Browse.jpg

Step 5: You will see an error such as "This Operation requires IIS integrated pipeline mode" in your browser.

IISPipelineMode.jpg

Note: Please don't close the browser.

Step 6: Select "Advanced Settings" of your site in the Application Pool by right-clicking and selecting "Advanced Settings".

AdvanceSettings-in-Apppool.jpg

Step 7: Select Integrated in the Managed Pipeline Mode.

Integrated.jpg

Step 8: Reload your browser and you will see the Home Page.

HomePage-by-IIS.jpg

Step 9: Now click on "Register" and enter the details.

Register-in-IIS.jpg

Step 10: After registration you can login.

Login.jpg

HelloSumit.jpg

That's it.

Summary

So far, this article will help you to learn to create an MVC 5 Application to store the data and information in SQL Server directly and you don't need to worry about creating the database manually. With this article you can also learn to publish your article and browse your application from IIS Manager and the app will run on the IIS Server. So just go for it and let me know if you have any problem.

Thanks for reading my article.


Similar Articles