Saturday 3 December 2016

MVC Part 28

ASP.NET MVC - Useful Resources


The following resources contain additional information on ASP.NET MVC. Please use them to get more in-depth knowledge on this.

Useful Links on ASP.NET MVC

Useful Books on ASP.NET MVC

  • Learn ASP.NET MVC
  • ASP.NET MVC 5
  • Professional ASP.NET MVC 5
  • Pro ASP.NET MVC 5
  • Programming Microsoft ASP.NET MVC
  • Pro ASP.NET MVC Framework

MVC Part 27

ASP.NET MVC - Self-hosting

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.

MVC Part 26

ASP.NET MVC - Deployment

we will be covering how to deploy ASP.NET MVC application. After understating different concepts in ASP.NET MVC applications, now it’s time to understand the deployment process. So, whenever we are building any MVC application we are basically producing a dll file associated for the same with all the application settings and logic inside and these dlls are in the bin directory of the project as shown in the following screenshot.
Deployment

Publishing to Microsoft Azure

Let’s take a look at a simple example in which we will deploy our example to Microsoft Azure.
Step 1 − Right-click on the project in the Solution Explorer and select Publish as shown in the following screenshot.
Solution Explorer
Step 2 − You will see the Publish Web dialog. Click on the Microsoft Azure Web Apps.
Microsoft Azure Web Apps
It will display the ‘Sign in’ page.
Step 3 − Enter credentials for the Microsoft Azure Subscription.
Credentials
Once you’re successfully connected to your Azure account, you will see the following dialog.
Azure account
Step 4 − Click ‘New’ button.
New Button
Step 5 − Enter the desired information on the above dialog such as Web App name, which must be a unique name. You will also need to enter App service plan, resource group, and then select your region.
Desired Information
Step 6 − Click ‘Next’ button to continue.
Click Next Button
Step 7 − Click the ellipsis mark ‘…’ to select the connection string.
Ellipsis Mark
Step 8 − Select the server name and then choose the Windows Authentication option. Select the database name as well. Now you will see that the connection string is generated for you.
Generating Connection
Step 9 − Click ‘Next’ to continue.
Click Publish Web Next
Step 10 − To check all the files and dlls which we will be publishing to Azure, click the Start Preview. Click ‘Publish’ button to publish your application.
Once the application is successfully published to Azure, you will see the message in the output window.
Publishing Azure
Step 11 − Now open your browser and enter the following URL ‘http://mymvcdemoapp.azurewebsites.net/employees’ and you will see the list of employees.
Employees List
Step 12 − Now if you go to your Azure portal and click ‘App Services’, then you see that your application is deployed to Azure.
App Services
Step 13 − Click the name of your app and you will see the information related to that application such as URL, Status, Location, etc.
Related Information
We have seen so far how to publish a web application to Azure app, after the application is created. You can also create an application, which will be deployed to Azure.
Let’s create a new ASP.NET MVC application.
ASP.NET MVC application
Step 1 − Click Ok and you will see the following dialog.
ASP.NET Project
Step 2 − Select MVC template and also check Host in the Cloud checkbox. Click Ok.
When the Configure Microsoft Azure Web App Settings dialog appears, make sure that you are signed in to Azure.
Configure Microsoft Azure
You can see the default name, but you can also change the Web App name.
Step 3 − Enter the desired information as shown in the following screenshot.
Enter Desired Information
Step 4 − Select the ‘Create new server’ from the Database server dropdown and you will see the additional field.
Create New Server
Step 5 − Enter the Database server, username, and password. Click Ok.
Step 6 − Once the project is created, run the application and you will see that it is running on the localhost.
Run Application
Step 7 − To deploy these applications to Azure, right-click on the project in the solution explorer and select ‘Publish’.
Deploy Application
You will see the following dialog.
Select Publish Target
Step 8 − Click the ‘Microsoft Azure Web Apps’.
Click Microsoft Azure Web Apps
Step 9 − Select your application name from the Existing Web Apps and click Ok.
Select Application Name
Step 10 − Click the ‘Validate Connection’ button to check for the connection on Azure.
Validate Connection
Step 11 − Click ‘Next’ to continue.
Click on Next
Now you will see that the connection string is already generated by default.
Generated Connection String
Step 12 − Click ‘Next’ to continue.
Connection String Next
Step 13 − To check all the files and dlls which will be published to Azure, click the ‘Start Preview’.
Preview
Step 14 − Click ‘Publish’ button to publish your application. Once the application is successfully published to Azure, you will see the message in the output window.
Publish Button
You will also see that the application is now running from the cloud.
Cloud
Let’s go to Azure portal again. You will see the app here as well.
Azure Portal