+ All Categories
Home > Technology > ASP.NET Web Stack

ASP.NET Web Stack

Date post: 12-Dec-2014
Category:
Upload: ugo-lattanzi
View: 1,719 times
Download: 0 times
Share this document with a friend
Description:
What new with ASP.NET 4.5 and ASP.NET MVC 4, Web API and SignalR
Popular Tags:
47
VS2012 for Web Developers Ugo Lattanzi Microsoft MVP ASP.NET/IIS, MCP Twitter: @imperugo Blog: http://tostring.it E-mail: [email protected]
Transcript
Page 1: ASP.NET Web Stack

VS2012 for Web DevelopersUgo LattanziMicrosoft MVP ASP.NET/IIS, MCP

Twitter: @imperugoBlog: http://tostring.itE-mail: [email protected]

Page 2: ASP.NET Web Stack

Agenda

• ASP.NET MVC/Webform• Web API• SignalR

Page 3: ASP.NET Web Stack

WebStack

Page 4: ASP.NET Web Stack

ASP.NET MVC 4What’s new!

Page 5: ASP.NET Web Stack

New Release mode!

MVC 4, Web API, SignalR and so on are distribute by NuGet so you can update the packages directly into Visual Studio without download and install anything on your computer.

Page 6: ASP.NET Web Stack

New Template

• HTML5 Template (semantic tags, media queries, etc);

• It’s responsive (PC, Tablet and smartphone landscape/portrait)

Page 7: ASP.NET Web Stack

Async everywhere

Page 8: ASP.NET Web Stack

Asynchronous operations• The async is available also for ASP.NET

• MVC/Webform/WebAPI supports async/await keywords for long running action (I/O, Web Requests and so on);

Page 9: ASP.NET Web Stack

Asyn Controller

Page 10: ASP.NET Web Stack

Bundle Minification

Page 11: ASP.NET Web Stack

Bundle minification

Bundling and minification are two techniques you can use in ASP.NET 4.5 to improve request load time.  Bundling and minification improves load time by reducing the number of requests to the server and reducing the size of requested assets (such as CSS and JavaScript.)

Page 12: ASP.NET Web Stack

Bundle minification

Using B/M Without B/M Change

File Requests 9 34 256%

KB Sent 3.26 11.92 266%

KB Received 388.51 530 36%

Load Time 510 ms 780 ms 53%

Page 13: ASP.NET Web Stack

• Debug mode;• Reduce the number of requests;• Reduce the file size;• Custom Bundles;• CDN Support;• Directory Support;• LESS, CoffeeScript, SCSS, Sass Bundling

Bundle minification

Page 14: ASP.NET Web Stack

Debug bundle

Page 15: ASP.NET Web Stack

Create new js bundle

using System.Web.Optimization;

bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js"));

bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include("~/Scripts/jquery-ui-{version}.js"));

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.unobtrusive*","~/Scripts/jquery.validate*"));

Page 16: ASP.NET Web Stack

Create new css bundle

using System.Web.Optimization;

bundles.Add(new StyleBundle("~/Content/themes/base/css").Include("~/Content/themes/base/jquery.ui.core.css","~/Content/themes/base/jquery.ui.resizable.css","~/Content/themes/base/jquery.ui.selectable.css","~/Content/themes/base/jquery.ui.accordion.css","~/Content/themes/base/jquery.ui.autocomplete.css","~/Content/themes/base/jquery.ui.button.css","~/Content/themes/base/jquery.ui.theme.css"));

Page 17: ASP.NET Web Stack

Custom Transformation

using System.Web.Optimization;

public class LessTransform : IBundleTransform{ public void Process(BundleContext context, BundleResponse response) { response.Content = dotless.Core.Less.Parse(response.Content); response.ContentType = "text/css"; }}

Page 18: ASP.NET Web Stack

Mobile Support

Page 19: ASP.NET Web Stack

Mobile support

• Mobile Template;• Device auto detect (mobile/desktop);• Support to mobile views (.mobile.cshtml);• Manual Check (Request.Browser.IsMobileDevice);• Override

HttpContext.SetOverriddenBrowser(BrowserOverride.Desktop);

Page 20: ASP.NET Web Stack

Mobile support

DisplayModeProvider.Instance.Modes.Insert(0, newDefaultDisplayMode("iPhone"){ ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf ("iPhone", StringComparison.OrdinalIgnoreCase) >= 0) });

Page 21: ASP.NET Web Stack

Social Network

Page 22: ASP.NET Web Stack

Social Network

• Enabling Logins from social networks (Facebook, Twitter, Google, LinkedIn, Live, Yahoo)

• Retrieve data after social login;• Easy to setup (just add your api key/secret into AuthConfig.cs)• Using DotNetOpenOAuth;

Page 23: ASP.NET Web Stack

More and more

Page 24: ASP.NET Web Stack

More stuff

• JSON.NET• Empty Project Template;• Azure SDK (1.6);• Database Migrations;• Add Controller to any project folder

Page 25: ASP.NET Web Stack

Demo

Page 26: ASP.NET Web Stack

Questions?

Page 27: ASP.NET Web Stack

Web API

Page 28: ASP.NET Web Stack

Web API and REST

When you speak about Web API, probably you should know REST, but was doesn it mean?

REST= REpresentational State Transfer

Page 29: ASP.NET Web Stack

Web API

It is not a WebService, a patter or a protocol, but is a style of software architecture for

distributed systems such as the World Wide Web

Page 30: ASP.NET Web Stack

Web API

ASP.NET Web API is a framework (FW 4.0) for processing data and returning data, tipically in json or xml (RESTful services);

It seems MVC but is not and, if you need both, use both.

Page 31: ASP.NET Web Stack

What is similar to MVC?

• Released with NuGet;• Routing;• Controllers and Actions;• Filters;• ModelBindings;• Dependency Injection;

Page 32: ASP.NET Web Stack

What is different from MVC?

• Dispatching (based on http verbs);• Formatters;• Async everywhere;• Self host (no need IIS);• Content negotiation;

• Everything is under System.Web.Http;

Page 33: ASP.NET Web Stack

How does it work?public class ValuesController : ApiController{// GET api/valuespublic IEnumerable<string> Get(){return new string[] { "value1", "value2" };}

// GET api/values/5public string Get(int id){return "value";}}

// POST api/valuespublic void Post([FromBody]string value){}

// PUT api/values/5public void Put(int id, [FromBody]string value){}

// DELETE api/values/5public void Delete(int id){}}

Page 34: ASP.NET Web Stack

Conventions

If you don’t like the conventions, don’t worry you can override using the attributes [HttpGet] and [NoAction]

Page 35: ASP.NET Web Stack

Client

Into System.Web.Http (assembly Microsoft.AspNet.WebApi.Client) there is also a client.

HttpClient client = new HttpClient();var requestUrl = new Uri("http://api.mysite.com/something");var response = client.GetStringAsync(requestUrl);

Page 36: ASP.NET Web Stack

Errors handling

• By default the response in 500;• You can manage differently in a single response, or writing a

different default behavior.

Page 37: ASP.NET Web Stack

Errors handling• By default the response in 500;• You can manage differently in a single response, or writing a

different default behavior.

public string Get(int id){ if(id<1) throw new HttpResponseException(HttpStatusCode.NotFound);

//DO SOMETHING return "value";}

Page 38: ASP.NET Web Stack

Content Negotiation

• The response format depends from the client;• You can add custom formatters for the response, out of the box

json and xml are supported;

Page 39: ASP.NET Web Stack

Demo

Page 40: ASP.NET Web Stack

Questions?

Page 41: ASP.NET Web Stack

SignalR

Page 42: ASP.NET Web Stack

SignalR

Async signaling library for .NET to help build real-time, multi-user interactive web applications ( aka persistent connection abstraction for .NET);

Install-Package SignalR;Install-Package SignalR.SampleMIT License

Page 43: ASP.NET Web Stack

SignalR

• Web Sockets (several fallback like «forever frame» and «Long polling»);

• Different clients (JS, Silverlight, Window8, WPF, Windows Phone);

Page 44: ASP.NET Web Stack

super-Demo

Page 45: ASP.NET Web Stack

Questions?

Page 46: ASP.NET Web Stack

THANKS

Page 47: ASP.NET Web Stack

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.


Recommended