ASP.NET MVC - Self-hosting



In this chapter, we will cover Self-Hosting. Self-Hosting creates a runtime environment for the application to run in any environment say MAC, or in Linux box, etc. Self-Hosting also means it will have a mini CLR version.

Deploy using File System

Let’s take a look at a simple example of self-hosting.

Step 1 − Once your ASP.NET MVC application is completed and you want to use selfhosting, right-click on the Project in the solution explorer.

Use Self-Hosting

You will see the following dialog.

Self-Hosting Dialog Box

Step 2 − Click the ‘Custom’ option, which will display the New Custom Profile dialog.

New Custom Profile dialog

Step 3 − Enter the profile name and click Ok.

Enter Profile Name

Step 4 − Select the File System from the Publish method dropdown list and also specify the target location. Click ‘Next’ button.

Select File System

Step 5 − Expand the File Publish Options.

File Publish Options

Step 6 − Check the ‘Delete all existing files prior to publish’ and ‘Precompile during publishing’ checkboxes and click ‘Next’ to continue.

Delete all Existing Files

Step 7 − Click ‘Publish’ button, it will publish the files at the desired location.

Publish Files at Desired Location

You will see all the files and folders in the target location on your system.

Target Location

It will have all the files required to get deployed on the localhost.

Step 8 − Now open the Turn Windows Feature on or off and Expand Internet Information Services → World Wide Web Services → Application Development Features.

Open Turn Windows Features

Step 9 − Check the checkboxes as shown in the above screenshot and click Ok.

Step 10 − Let’s open the IIS Manager as shown in the following screenshot.

IIS Manager

Step 11 − You will see different connections on the left side of the screen, right-click on MyWebSite.

Different Connections

Step 12 − Select the ‘Convert to Application’ option.

Convert to Application

As you can see, its physical path is the same as we have mentioned above while publishing, using the File system.

Step 13 − Click Ok to continue.

Click OK

Now you can see that its icon has changed.

Step 14 − Open your browser and specify the following URL http://localhost/MyWebSite

Specify URL

You can see that it is running from the folder which we have specified during deployment.

Advertisements