How To Host ASP.NET MVC 5 And Web API On IIS For Development Purposes

Introduction

ASP.NET Web API and ASP.NET MVC 5 are more difficult for some developers to host on IIS for development purposes. We know to just press the Windows key + R and type inetmgr. Afterwards, go to Visual Studio. Right click on the project properties and under the Web tab, create the virtual directory for our Web app and Web API easily but with the arrival of ASP.NET MVC 5, latest architecture and tools there are some difficulties to host on IIS for the development purposes. 

Explanation

When we want to create an Android or an IOS app, JSON is the most important part for the data exchange. Every mobile developer needs JSON to send back and forth data but after the arrival of ASP.NET MVC5 and latest tools for API, there is too much difficulty for the developers to host the app on the IIS on Windows environment and to test the Application. This type or problem was encountered, when I was doing my BCS final year project. My project was based on the Web as well as an Andriod Application. I want to test the Web API but there are a lot more issues to host Web API or Web apps on IIS.

How to?

  • First of all, open IIS method, which is Windows key + R and then type inetmgr. If some error or issue happens, then go to Control Panel, select Programs and features. Click Windows Feature on and off and make sure your IIS feature is checked. If not checked, then check it.

    MVC5
  • Open Visual Studio and then make your ordinary Web or Web API project, which is you want to host on IIS or even the existing project

  • Right click on the Project. Go to properties->Web->Servers. Select Local IIS and click to create virtual directory

    MVC5
  • Go to the Browser and hit the Project URL. You will get the error, as shown below.

    MVC5
  • The main issue is how to resolve this type of error. Yu can change the module, tbut hen you get this error again, and again This type of error is not associated with any default page which may be IIS and ASP.NET Web forms which suggest you set the default pages.

  • After studying a lot more, I found the solution to this type of error.

  • If we see the packages of our ASP.NET MVC Application, we see that the version of .NET, which we use is 5.2.3.

    MVC5
  • The main reason behind this error is by default when we install Windows, the Application development features for the latest ASP.NET tools are disabled, which leads to the this kind of problem.

  • To solve this issue, go to Control Panel-> Windows feature On or Off

    MVC5

    MVC5

    Select these features under Application development Features. By default, some of these features are disabled.

    Click OK to apply all the changes.

  • Hit the project URL in the Browser and your Application work correctly without any error.

    MVC5
The same process with ASP.NET Web API needs to be followed.