Thursday 13 February 2014

ASP.NET MVC 4 Fundamentals

 

 

Introduction to ASP.NET MVC 4 Part 1

 

Release notes of ASP.NET MVC 4

 

image

 

 

 

Demo of MVC4

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

 

Model, View and Controllers

 

image

 

 

 

image

 

 

 

Database Migrations

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

To control the DB creation in Entity Code first model

 

image

 

 

 

Modify Connection string in WEB Configuration of Application

 

image

 

 

 

 

Showing Data into MVC Application pages

 

image

 

 

 

image

 

 

 

image

 

Note:  Above only for particular Http Request context

 

 

 

image

 

 

 

 

 

image

 

 

 

image

 

 

image

 

 

 

 

 

Introduction to ASP.NET MVC 4 Part 2

 

Listing Data

 

image

 

 

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

 

Creating Data

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

image

 

 

 

image

 

 

 

 

image

 

 

 

image

 

 

 

Authorization

 

Default Authorization modules in ASP.NET MVC

image

 

 

 

image

 

 

 

image

 

 

 

Use default provider of .NET framework for authorization

 

image

 

 

 

image

 

 

image

 

 

 

image

 

 

image

 

 

 

A work about Security

image

 

 

 

image

 

 

 

Deploying to the Cloud

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

To publish website into Cloud network

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

 

 

Web Optimization with ASP.NET MVC

 

image

 

 

 

The Scenario

 

There is a home controller and there is an index vies but they do almost nothing but just render some simple text so far. But I do have the application set up with a lot of the infrastructure that I need later on.

image

 

 

 

So if we look in the lay out here you can see I am including bootstrap,bootstrap.css is a css framework you can include in the project.  I also have my own custom stylesheet, styles.css included, and the JavaScript library modernizr.  I am including modernizr at the top of this file because as you might know modernizr is a library  that detects features in a browser and in a few cases adds HTML5 capabilities to older browsers.

image

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

 

image

 

 

 

image

 

Note:

You can see the jQuery was almost 250 kilobytes, jQuery Y was over 360 kilobytes.

 

 

 

 

image

 

Note:  And this is the scenario that asp.net web optimization set out to improve.

 

 

 

WEB Optimization Framework Installation

 

image

 

 

 

image

 

 

 

image

 

 

 

Configuring Web Optimization Tool

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

The Results are in

 

image

 

 

Note:

Here to the network tab click on start capturing and let's refresh this URL. 10 different downloads we only have 4 downloads, Internet Explorer is able to do all of these concurrently and we're not going to have to wait too long hopefully for this final result to come in.  In 20 seconds that's compared to almost 60 seconds before, We delivered a total of 433 kilobytes, that's compared to 897 kilobytes before.  Some bundling and minification roughly cut the number of bytes that we sent to the client in half and it cut the time it took to load all of the assets for this page by more than half.

 

 

 

 

The ASP.NET WebAPI

 

We have been using Web services to communicate with other devices in network.  It’s has been using WCF-SOAP or Web service-SOAP protocol to transfer messages.  SOAP-based web services generally required a tool kit and more processing power.

image

 

 

 

 

HTTP is everywhere, it's lightweight and you can use it to exchange information with big servers as well as small devices like mobile phones. So faced with the shift in web services, the Windows Communication Foundation team at Microsoft began working on a new framework that is now part of ASP.NET and is called web API. The ideas that WCF is still a great technology when you're writing enterprise services  and it can use toolkits but the web API is going to be more focused on being lightweight, highly interoperable, and using HTTP all the way.

 

image

 

 

 

Now, we know that the web API is a framework for building web services on top of HTTP.  and web API is going to allow us to easily consume XML or JSON.  that it has very similar features and concepts to ASP.NET MVC.

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

 

Routing for Web API

 

With the web API, the HTTP method being used plays a role.  The HTTP method is the verb used in the HTTP message.  and the common verbs are get, post, put, and delete.  You an also handle additional verbs if you need to do something like webDAV. You can do that and handle additional verbs by using an except verbs attribute. The web API also registers these routes slightly differently  since there is no action that's going to be in the URL for the routing engine.

 

image

 

 

image

 

 

 

To test this WEB API approach, we could use below URL and Tool

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

 

Content Negotiation

 

image

 

 

 

image

 

 

 

image

 

 

 

 

image

 

 

 

Parameter Binding

 

image

 

 

 

image

 

 

 

image

 

 

 

 

Implementing GET

image

 

 

 

image

 

 

 

image

 

 

 

And that actually simplifies things a bit if I just turn off the proxy creation.

 

image

 

 

 

image

 

 

 

Showing Data

image

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

XML Client with WEB API

image

 

 

 

image

 

 

 

image

 

 

 

 

Async and Await in MVC4

 

Synchronous operation in WEB application

 

if a web serve is called, it takes 250 milliseconds and the processing thread has to sit idle for 250 milliseconds.  If all the threads are tied up and idle, and any new HTTP request that are arriving  at the server, ASP.NET will queue them up and force them to wait for one of this request processing threads to free out.

image

 

 

 

Old method of Async operation in MVC3

 

you needed to inherit from the async controller base class instead of the regular controller base class.

 

image

 

 

 

 

With ASP.NET MVC 4, it's much easier to keep our request thread busy.  We can free our threads out from running long input output operations and I want to make clear what we're going to talk about in this module is asynchronous behaviour on the server.  What we're going to cover has nothing to do with Ajax or asynchronous calls on the client.

image

 

 

 

 

Task Parallel Library and the async and await keywords of C#.

 

The Task Parallel Library or TPL has been around in the .NET framework since version 4.  so you can run work in parallel or asynchronously and not have to worry about partitioning work and scheduling threads and some of the other low level details.  Although the TPL is very god at a number of things like parallel processing,  we're going to focus on using the library for asynchronous processing.  On the web server, we're usually not as interested in parallel processing as we are  in keeping request threads busy which is you think about it, it's already a form of parallel processing because multiple HTTP request can be executing in parallel.

 

 

image

 

 

 

Console mode program which runs some operations in Sequence.

 

image

 

 

 

out our numbers then we can show the result and everything happens on the same thread.

 

image

 

 

 

Console mode program which runs some operations in Parallel.

 

image

 

 

 

image

 

 

 

 

Async and Await operation

 

Async in a way essentially provide cooperative multitasking for a thread so it can stay hot.

 

image

 

 

 

 

image

 

 

 

image

 

 

 

 

Async Controller

image

 

 

 

Async Action

image

 

 

 

 

Async and Parallel

 

So the other thing to notice about this, we're still doing this operations and serial.  so the elapsed time to render was still over 4000 milliseconds and that's because where waiting for the headline call to complete before we go A different way we could do this if we wanted things to operate in parallel  and that is I don't want to await as soon as I call, it GetHeadlineAsync. Instead, I could say that we could store this into the headline Task variable

 

image

 

 

image

 

 

 

Same operation in Parallel mode

 

image

 

 

 

 

Async Timeouts

 

image

 

 

image

 

 

image

 

 

 

Async Exceptions

image

 

 

 

Async Testing

 

image

 

 

image

 

 

 

 

MVC 4 and Mobile Development

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

 

Display modes

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

that by default the runtime uses an ASP.NET browser capability provider that by default the runtime uses an ASP.NET browser capability provider

 

image

 

 

 

image

 

 

 

image

 

 

image

 

 

image

 

 

 

Custom Display mode

 

image

 

 

image

 

 

 

Browser overriding

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

 

 

Blogger Labels: Fundamentals,Introduction,Part,Release,Demo,Model,View,Controllers,Database,Migrations,creation,Code,Modify,Connection,Configuration,Application,Data,Note,Above,Request,context,Authorization,Default,modules,provider,framework,Cloud,Optimization,Scenario,controller,index,text,infrastructure,custom,JavaScript,library,capabilities,Installation,Tool,Results,Here,Internet,Explorer,Some,client,assets,WebAPI,SOAP,protocol,messages,information,servers,Windows,Communication,Foundation,team,Microsoft,technology,enterprise,JSON,concepts,method,role,message,action,engine,Content,Negotiation,Parameter,proxy,Async,Await,Synchronous,server,output,module,behaviour,Ajax,Task,Parallel,version,Although,Console,mode,Sequence,GetHeadlineAsync,Instead,Same,Timeouts,Exceptions,Mobile,Development,Display,modes,Browser,bootstrap,modernizr,jQuery,kilobytes,verbs,milliseconds,asynchronous,runtime

No comments:

Post a Comment