Wednesday, April 23, 2014

MVA Course: Developing ASP.NET MVC 4 Web Applications Jump Start (Modules 7 & 8)

Covered deploying to Azure, SignalR, and new features in Visual Studio 2013.








*******************************************************************************************
MODULE 7
*******************************************************************************************

// azure is a great resource for developers
// azure you can get 10 free website, 20 databases, free bennies with MSDN

Lesson 1: Deploying a Web Application
ASP.NET MVC 4 Dependencies
Deploying Web Applications to Single Server Farms
Deploying Web Applications to Multi-Server Farms
Deploying Web Applications on Windows Azure
Demonstration: How to Create a Windows Azure Website

ASP.NET MVC 4 Dependencies
ASP.NET MVC 4 dependencies include:
The ASP.NET Framework 4.0 Common Language Runtime (CLR)
The MVC 4 runtime //can be bin deployed, don't need gak(sp?) deploy...
A Database server
Entity Framework
Membership Providers
Question: Why should we use specific mapping for IIS 6.0 or earlier or IIS 7.0 in classic mode?
Answer: We should use specific mapping for IIS 6.0 or earlier, because these versions of IIS are not configured to route all request to ASP.NET engine.
You can mention that mapping all requests to ASP.NET engine is a good approach, because it will not require changes to applications. This approach eliminates the need to retest the application.
Different techniques for deploying such dependencies are covered later in this module.

Deploying Web Applications to Single Server Farms
To deploy an application on a single server farm:
Set up the web application in IIS
Configure application pools
You can run many applications in the same application pool
You can install an application in a specific isolated application pool
Copy the web application files to IIS
Question: What is the purpose of configuring additional application pools?
Answer: Configuring additional application pools allow different application configurations, such as user accounts.
You can use a dedicated application pool for each application to allow dedicated IIS process to handle requests for different application to increase redundancy.
Using the Visual Studio deployment tools to copy web application files to an IIS web server is covered in detail, in Lesson 2.
//web deploy is built into Visual Studio
// single server environment is not the most common apparently...

Deploying Web Applications to Multi-Server Farms
Characteristics of deploying applications to multi-server farms:
Multi-server web farms help increase performance, resilience, and reliability
It has greater capacity than a single server farm
To deploy your web application to a multi-server farm:
Create IIS applications and application pools on each server
Create a matching IIS configuration on each server
Use external hosted session state or session affinity
Configure machineKey element in the web.config file
Question: What is the purpose of configuring the machineKey element in the web.config file?
Answer: Configuring the machineKey element ensures that the same key is used for encrypting and decrypting content stored in the session state or configuration file.
// have to make sure the machine key is in sync
// set affinity so that a given user stays with a specific machine... kinda defeats
// the purpose though
// should just set up machine key across machines in the farm.
// best to avoid using session state...

Deploying Web Applications on Windows Azure
To deploy an application on Windows Azure:
- Create a new web application in the Windows Azure management portal
- Download a publishing profile
- Start the Publish wizard and import the publishing profile
- Configure connection strings
Observe that Microsoft Visual Studio publishes the web application on Windows Azure
Question: How does Windows Azure cloud services help enhance the flexibility of the application?
Answer: Windows Azure cloud services help separate user interface logic that you build in a web-role project, from business logic that you build in a worker process project. This separation provides greater flexibility, and it enables calling the business logic from other processes, such as mobile applications.
You can use Microsoft Visual studio to deploy applications to Windows Azure. However, to avoid accidental deployment to Windows Azure, you may wish  to avoid using Microsoft Visual Studio for deployment. Instead, They use service packages, since they provide more control over the deployment process.
//azure can automatically provision resources.

Reviewing Configuration for Production
While reviewing the configuration for production:
Include the transformation elements in the following web.config transformation files for generating resultant web.config files:
Web.release.config
Web.debug.config
Modify the web.config file by using the debug, xdt:Transform, and Insert attributes
Question: How can you configure the web.config file for publishing to a production environment, without using web.config configuration files?
Answer: You can edit the web.config file manually. Such a configuration will apply to production, debug and other configurations.
You can add additional web.config transform files for use in different configurations.

[DEMO]
// web.config transforms allow you to set up for release and debug...
// "Download Publish Profile" creates a file that you open in your project to set up the
// deployment
// if you are using EF Code first, you much use migrations to deploy
// migrations show up in the "migrations" folder
// migrations are a way of keeping model and database in sync over time
// package manager: enable-migration, add-migration, update-database
// migrations will only go if they are safe... that is, it won't let you lose data...
// if you'll lose data, you can use update-database -force
// package manager acta a bit like power shell
// initial deployment pushes everything, subsequent updates are differential

*******************************************************************************************
MODULE 8
*******************************************************************************************

Introducing SignalR
Abstraction over transports
Events instead of task/async
Connection management
Broadcast or target specific client

What does SignalR do?
Client to Server persistent connection over HTTP
Easily build multi-user, real-time web applications
Auto-negotiates transport
// http is stateless - user sends request, server sends response, then the server
// forgets about user. No true two way communication
// websockets can solve this problem, but there is a lot of low level stuff that has to
// happen. SignalR does some of this for us

SignalR Fallback
WebSockets
Server Sent Events
Forever Frames
Long Polling
// websockets is the first choice, but it may not be available, so it gracefully degrades
// to other methods

What does SignalR do?
Allows server-to-client push and RPC
Built async to scale to 1000’s of connections
Scale out with Service Bus, SQL Server & Redis
Open Source on GitHub
// you can do remote procedure calls when you can assume there is a two way connection

SignarlR Hub - Server
public class ChatHub : Hub
{
   public void SendMessage(String message)
   {
      Clients.addMessage(message);
   }
}
// inherits from hub, lets us register hubs
// we want "SendMessage" to be callable from the client in JavaScript
// SignalR generates the javascript file for us to provide this functionality
// SignalR handles casing (camelCase vs PascalCase)
// Clients is a dynamic object
// we just call a method, we don't have to deal with websockets

Chat with SignalR Hubs
var hub = $.connection.chat;
hub.addMessage = function (message) {
   $("#msgs").append("<li>" + message + "</li>");
};
$.connection.hub.start().done(function () {
   $("#send").click(function () {
      hub.sendMessage($("#msg").val());
   });
});
// this is on the client side
// the chathub will be in the javascript file that SignalR created
// the message listener for message is just a jQuery call...
// we can use hub.sendMessage to send data back to the server
// start().done makes sure that the connection is ready to go

[DEMO] Using ASP.NET SignalR
// signalr is available as a Nuget package.
// to make signalr work, it needs to be included in routing
// need to register hub in global aspx
// need a reference for signalr <script src="~/signalr/hubs"></script>
// you can send a message to all connected users, the caller, or a group
// add a client to a group by using Groups.Add(Context.ConnectionId, <groupid>)
// signalr is on the test apparently...
// ASP.NET, Learn, SignalR for lots of

Visual Studio 2012.2
// Brougt in signalr, web api, single page MVC, facebook
// Better page inspector and intellisense

Visual Studio 2013 RC
One ASP.NET
Browser Link
New HTML editor
Azure website tooling
Scaffolding
Owin
ASP.NET Identity
// plays well with VS2012
// ASP.NET is common frameword for MVC, SignalR, Web Forms, SPA, Facebook...
// Browser link - live update to browser when you make changes in visual studio using
// signalr
// Azure web tooling build into VS. publish profile can be accessed directly from visual
// studio
// Scaffolding - MVC, Web Forms, and Web API all use the same scaffolding system
// Open Web Interfaces for .NET - lets you plug in middleware
// ASP.NET identity improvements. solves problems with extending

[DEMO] VS 2013 and MVC 5
// consolidated authentication
// MVC 5 uses bootstrap
// vs web essentials is extensions for visual studio

Resources:
// @geektrainer, @jongalloway - twitter handles
// www.asp.net/feedback
// Web Camps -
//    www.devcamps.ms
//    aka.ms/webcamps-training-kit
// www.windowsazure.com - click on .NET...
// Microsoft Official Courseware -
// 20486 (and 20480 and 20487)




No comments:

Post a Comment