ASP.NET Core 2.0 Fundamentals -

ASP.NET Core 2.0 Fundamentals -

ASP.NET Core 2.0 Fundamentals Scott Sauber @scottsauber Audience Existing ASP.NET developers People interested in the new ASP.NET Core stack People using ASP.NET Core 1 Who am I?

Software Developer, working primarily with web and ASP.NET Worked with the .NET since 2009 Avid learner Following ASP.NET Core since the early days Agenda Split into 2 halves Intro to ASP.NET Core in general

What is ASP.NET Core? What is .NET Core? What stayed the same? What changed? New Features Whats new in ASP.NET Core 2.0 Demos all throughout

Questions any time History Lesson 1996 Classic ASP 2002 ASP.NET 2008 ASP.NET MVC 2010 ASP.NET Web Pages 2012 ASP.NET Web API and SignalR May 2014 ASP.NET vNext announced February 2015 ASP.NET vNext named to ASP.NET 5 January 2016 ASP.NET 5 renamed to ASP.NET Core 1.0

June 27, 2016 ASP.NET Core 1.0 RTM November 16, 2016 ASP.NET Core 1.1 June 28, 2017 ASP.NET Core 2.0 Preview 2 ASP.NET Core 2.0 RTM coming in A month or so from July 11th What is ASP.NET Core? Ground up rewrite Modular, pay for play via NuGet packages Improved performance Downside explicit about wiring up what you need Templates help solve this

Microsoft.AspNetCore.All Open source Cross platform (Windows, Mac, various flavors of Linux, containers) Its just a console app Runs on .NET Framework and .NET Core What is .NET Core? Cross platform .NET Trimmed down version of .NET Framework to get it to run crossplatform

.NET Core? Trimmed down API Some things missing (some temporary, some permanent) Missing permanently: Registry (Windows thing) Missing for now System.Drawing Windows port coming soon System.DirectoryServices Windows port coming soon

How to see if your code can run on .NET Core .NET Portability Analyzer Upload your packages.config and see if you can run .NET Core ASP.NET Core runs on top of .NET Core (and .NET Framework) .NET Core 2 is coming soon and is adding tons more APIs Source: Microsoft

.NET Core LTS vs. Current Which one to choose LTS Dont care about new features Dont want to upgrade right away

Want to be supported for a long time Support for 3 years after release or 1 year after subsequent LTS release, whichever is shorter Latest LTS version is .NET Core 1.0.5 Current Want new features Willing to upgrade frequently Support for 1 year after release or 3 months after subsequent Current release, whichever is shorter. Latest Current version is .NET Core 1.1.2

New major/minor releases every 6 months New patch releases every 2-3 months New .csproj project system Still uses msbuild Manage NuGet packages in csproj No more packages.config No more hint paths Slimmed down csproj Hello World down from ~300+ lines to ~20 lines

In the folder, in the project by default Can manually exclude files Live Edit csproj without needing to unload and reload Only works in ASP.NET Core/.NET Core projects today New csproj coming to older .NET projects later this year per Scott Hunter at DevIntersection Old vs New .csproj side-by-side MVC 5 Template

321 lines ASP.NET Core MVC Template 22 lines (really 19 lines without blank lines) dotnet CLI What is a CLI? Restore, Build, Run, Publish, New project all from the command line dotnet restore

dotnet run Installed with the .NET Core SDK (download at Cross platform (Windows, Mac, Linux) with any editor (VS, Code, Sublime, vim, emacs, Notepad if you like pain, etc.) Works for any .NET Core app, not just ASP.NET Core Demo dotnet SDK Core libraries and msbuild tasks for what everything runs on top of (including VS, CLI, etc.)

Also contains the .NET Core Runtimes (Current and LTS), all the Microsoft NuGet packages, and the CLI Offline restores Different versions can run side-by-side Just a folder, easy to uninstall C:\Program Files\dotnet\sdk One install to get you all the things If you use Visual Studio you dont have to

worry about the dotnet SDK its used by Visual Studio behind the scenes Lets get back to ASP.NET Core ASP.NET Core whats different than ASP.NET 4 ASP.NET Core is simply a console app. Web Forms is gone WCF server is gone Client side package management

web.config is only around for IIS compatibility Global.asax is gone Startup.cs Middleware all the things, even MVC Order matters New Features over ASP.NET 4 Save and reload, no more building Dependency Injection built-in Ship the framework with the app, side-by-side on the same server as other apps with different versions of .NET

Environments are a first class citizen TagHelpers > Html Helpers HtmlHelper:@Html.ActionLink("Home", "Index", "Home") class="btn btn-primary" asp-controller="Home" TagHelper: Home asp- MVC Wheres my cheese? MVC and Web API Controllers have been unified

No more ApiController, just inherit from Controller Child actions gone in favor of View Components /Views/_ViewImports.cshtml is your new /Views/web.config Instead of Just @using MyNamespace.Something Static files now served by folder called wwwroot I treat wwwroot as my bin directory. Source files live elsewhere and bundler puts them in wwwroot

MVC Whats the same? ASP.NET MVC Concepts are the same Still have Controllers Controllers still have Actions Still have Views Still have partial views

HTML Helpers still exist But you should use Tag Helpers Kestrel Brand new web server Built on libuv for now Cross platform

Kestrel On The Edge With 2.0, can now put it on the edge and be supported But they still recommend you still use a reverse proxy IIS on Windows nginx or Apache on Linux Why? IIS took 7 years to harden. Kestrel is 2 years old Barry Dorrans talk on Kestrels Security (4:55 to 6:35)

Kestrel with Reverse Proxy Image: Rick Strahl Kestrel (continued again) High performance The stuff they do is crazy in the name of perf More details: TechEmpower Benchmarks What are the TechEmpower Benchmarks? ASP.NET Core 1.7M requests per second PHP: 44K Django: 88K Node: 429K This is a plain text this is essentially hello world Power of Open Source #2 contributor to Kestrel, Ben Adams, is a non-Microsoft Employee This is where modularity is crucial

Lets talk about 2.0 Currently in preview 2 w/ preview VS tooling RTM in about a month A move towards simplicity Razor Pages dotnet CLI changes Restore implied New, Customizable Templating Engine

TagHelperComponent Inject in something (like JS/CSS/etc.) to beginning or end of Head or Body Precompilation of Views happens on publish by default Authorization got an overhaul Program.cs is Simplified ASP.NET Core 1: ASP.NET Core 2:

Microsoft.AspNetCore.All Simplifies Dev Metapackage Contains ALL the packages Microsoft ships (AspNetCore, EF, etc.) Simplicity of managing versions Simplicity in oh I need another NuGet package now Publish will trim out your packages you dont need Utilizes the Runtime Store More on this later Publish will also pre-compile views by default

Improve startup time of views .NET Core 2 feature only (not full framework) Microsoft.AspNetCore.All Simplifies Packages Single version instead of multiple Why was it multiple in 1.0? Didnt rev all packages if the package didnt change ASP.NET Core 1:

ASP.NET Core 2: Runtime Store Take assets from NuGet package and put them in a global location on the machine The GAC is back baby! The NuGAC Optimizes the packages by CrossGening that pre-JITs the assemblies Improves startup time 1.x 3s

2.x 1s By default, all Microsoft packages (Microsoft.AspNetCore.All) are included in Runtime Store via .NET SDK install Improves the Publish Size of App 1.x 16MB MVC Hello World 2.0 4MB MVC Hello World .NET Core 2 feature only (not full framework) Whats wrong with Controllers

Today? Can easily get bloated with lots of actions and logic if youre not careful Inject in all dependencies for all actions, even though rarely does any action use all dependencies Can be hard to navigate Look at AccountController.cs in the templates 500ish lines of gobbly gook Introducing - Razor Pages Page focused approach over Controller focused approach

I like this concept a lot. Focusing on a single page, GET and POST Dependencies just inject what it needs Rarely working on multiple actions/pages at once when working on a bug or feature. Almost always working on a single page. Deconstructing Razor Pages View Page Register.cshtml Minor difference from MVC`

PageModel page Register.cshtml.cs Code behind is back! Inherits from PageModel Think of it like a mini Controller, but it also includes your ViewModel

Thats it! Nothing special to wire up in Startup.cs. .AddMvc adds RazorPages Because its just MVC under the hood. Razor Pages Differences from MVC Controllers are gone Controller logic of GET, POST, etc. is now in a code behind file with Page Handlers like OnAsync such as OnGetAsync or OnPostAsync Register.cshtml.cs Async optional

Default Pages folder is /Pages instead of /Views Configurable via .AddRazorPagesOptions() off of AddMvc Top of view define @page Razor Pages Replacing HTML MVC (not APIs) Razor Pages will be the default ASP.NET Core Web Application template by ASP.NET Core 2.0 RTM MVC still available via an ASP.NET Core Web Application MVC template

We believe Razor Pages is a vastly superior way of doing server-side HTML generation. (than MVC) Damian Edwards Can use MVC and Razor Pages side-by-side Razor Pages is just an extension to MVC. Uses same things MVC does Partials Model binding Still a _ViewStart and _ViewImports Demo

File => New Project => Razor Pages and lets have a look around Lets convert an MVC action to a Razor Page Default Folders Page vs Views Code behind Inherit from PageModel OnGetAsync and OnPostAsync (and OnAsync) As well as Sync versions, just drop the Async Routing

Other Razor Pages benefits Anti-Forgery Validation happens automagically in Razor Pages No more [ValidateAntiForgeryToken] attributes Sidenote: if using ASP.NET Core MVC register the AutoValidateAntiForgeryToken attribute to your global filters My opinion on Razor Pages Love the concept of Page-focused vs. Controller focused Feels a bit incomplete/early Idiomatic Razor Pages still needs to be fleshed out

Putting View Model props inline on PageModel or still separate ViewModel file and single ViewModel prop on PageModel I lean the latter currently. No attribute routing I bet the design goes through a little churn as they get feedback Id wait and see unless you like being on the edge Good news here is most logic remains in tact between MVC => Razor Pages, with just the few caveats Ive shown This is why we CAN have nice things

EnvironmentTagHelper include and exclude Whats still coming 2.1 coming 6 months after 2.0 RTM SignalR will be part of 2.1 Things in MVC getting ripped out into being more full-stack Routing will be available in Middleware Improve Developer Inner Loop to sub-second Make a change anywhere, hit Save and browser autorefreshes in <1 second

How to stay on the bleeding edge/latest Watch the ASP.NET Community Standup almost every Tuesday for details Go to GitHub and select Watch on the Announcements repo Only issues created are for announcing breaking changes If this stresses you out dont do it. Just wait until things RTM and read the release notes.

How do I get started? Go to Click on Download Follow instructions for your OS of choice So should I switch to ASP.NET Core today? It Depends Its at least worth a hard look at this point But ASP.NET 4.x is still going to be supported for a long time

Resources Look in the /samples on GitHub Example: How to get ASP.NET Core ASP.NET Community Standup

ASP.NET Monsters ASP.NET Core Documentation ASP.NET Core Source ASP.NET Core roadmap

.NET Core roadmap Questions? Feel free to reach out on Twitter (@scottsauber) if you think of a question later Slides posted on my blog ( and Ill tweet them out Dont forget to fill out evals, please


Recently Viewed Presentations

  • Measures of Position

    Measures of Position

    Boxplot. A boxplotis a graph that presents the five-number summary along with some additional information about a data set. There are several different kinds of boxplots. The one we describe here is sometimes called a modified boxplot. Example: Boxplot.
  • Dramatic Structure of Shakespeare&#x27;s Plays

    Dramatic Structure of Shakespeare's Plays

    Tragic Hero acts because of his tragic flaw. Act I - Introduction. Exposition. The exposition provides the background information needed to properly understand the story, such as the protagonist, the antagonist, the basic conflict, and the setting. It .
  • Clery Act & Campus Security Authority (CSA) Overview

    Clery Act & Campus Security Authority (CSA) Overview

    Jeanne Clery was a 19 year old freshman at Lehigh University in Bethlehem, Pennsylvania. On April 5, 1986, she was murdered in her dormitory by a fellow student.
  • SEI Structure Development

    SEI Structure Development

    Input Optics (IO) Cost and Schedule Breakout Presentation NSF Review of Advanced LIGO Project David Reitze UF Input Optics Description & Deliverables The Input Optics conditions the light from the Pre-Stabilized Laser and sends it on to the main interferometer...
  • Iliad, Books 19-22 - Missouri State University

    Iliad, Books 19-22 - Missouri State University

    Iliad, Books 19-22 Book 19 - Armor presented The Shield Briseis returned Book 20 - Gods go to War Athena fighting with Diomedes Book 21 - Achilles fights the River River Scamander (or Xanthus) fights back.
  • Real Options - York University

    Real Options - York University

    Real Options in Capital Budgeting ... Call Option Valuation Option Valuation Parameters Option Valuation Re-evaluating the Lev-I The DCF valuation of the Lev-I was (205.63) The Lev-II option is worth 305.30 With the Lev-II option, the Lev-I is worth 99.67...
  • Andy Warhol -

    Andy Warhol -

    Today's lesson is about Indigenous Australian Artist Richard Bell, who also uses Pop Art style to create his works.What is a "propagandist'?Richard Bell uses a wide range of media including painting, performance, and video to challenge theway the viewer thinks...
  • DECam flatfield calibration - Fermilab

    DECam flatfield calibration - Fermilab

    DECamSpectrophotometric Calibration. DECam calibration workshop, TAMU April 20th, 2009. Jean-Philippe Rheault, Texas A&M University