ASP.NET and Visual Studio 2012 Robert Boedigheimer
About Me Web developer since 1995 Columnist for aspalliance.com Pluralsight Author 3 rd Degree Black Belt, Tae Kwon Do ASP.NET MVP
Visual Studio 2012 Project and solution “round tripping” –VS 2010 SP1 VS 2012 –Can use new editor features –Breaks if use.NET 4.5 features Quick Launch Solution explorer –Drill into classes and methods –Image thumbnails
Visual Studio 2012 (cont) Search everywhere Preview Tab Browser Chooser Turn off all caps –HKEY_CURRENT_USER\Software\Micros oft\VisualStudio\11.0\General\SuppressUp percaseConversion –REG_DWORD 1
Editor Improvements Editor Parity (HTML, CSS, JavaScript) –Brace matching –Regions –Outlining –Commenting –Formatting
HTML Editor Improvements Matching tag renaming Event handler setup (source view) Smart Tasks (source view) HTML 5 –IntelliSense for tags –Snippets –New doctype, missing some simplifications Attribute Code IntelliSense
JavaScript Editor Improvements ECMAScript 5 full support IntelliSense improvements Implicit References –Tools -> Options -> Text Editor -> JavaScript -> IntelliSense -> References Go to definition Uses IE 9 JavaScript engine
CSS Editor Improvements CSS 3 CSS Snippets Vendor specific prefixes Improved color picker (with opacity) Hierarchical Indentation Knows common “hacks” Comment/Uncomment
Page Inspector Install with Web Platform Installer Browser diagnostics in Visual Studio –Trace from web page to source code –View position in DOM –Trace CSS properties for element to the rule
Request Validation Previous ASP.NET approach –Validation by default –Turn off at site or page level Deferred request validation (only validate when access) –Request.Unvalidated.Form –Web Forms ASP.NET controls always accessed! ValidateRequestMode=“Disabled” to turn off for an ASP.NET control
Miscellaneous Publish profiles –Build configurations included in dialog (debug, release) IIS Express Performance –Interning – symbolic links to single shared assembly, aspnet_intern.exe, runs in.NET 4 –JIT compiles across processor cores (on by default) –GC tuning
Fiddler Tracing tool specifically for HTTP Shows complete request and response (not packets) Can save archive of session Transfer Timeline
Performance Rules For most web sites, only 10-20% of response time is waiting for the HTML document to be generated and downloaded –Not optimizing code! Make fewer HTTP requests Send as little as possible Send it as infrequently as possible
Bundling and Minification Make fewer HTTP requests Send as little as possible Minimize CSS and JavaScript files –Remove whitespace, comments, excessive semicolons, etc Bundle/combine to reduce number of HTTP requests Previous method –AjaxMinifier, MSBuild – –Home page was 46% faster!!
ASP.NET Bundling and Minification Runtime (but results cached in memory) Default order –Common libraries first (jQuery, etc) –Alphabetical Multiple bundles are ok API –Customize ordering of files –Customize transforms (CoffeeScript, LESS, etc)
Content Expirations Client asks “if-modified-since” Small content files it is just as expensive to see if modified as to receive content Leverage user’s browser cache Setup expiration times for content folders Avoid requests for files that seldom change (.js,.css, images, etc) Rename the file if need to override browser caching
ASP.NET Bundling and Minification (2) Add a hash value to bundle URLs –Take advantage of caches for repeat visitors –Change the URL to avoid cache when change files using ResolveBundleUrl( )
Asynchronous Improvements Asynchronous HTTP Modules and Handlers await – wait asynchronously for some other code to complete async – used to mark method as asynchronous task based method
IIS 8 Web Sockets –Bi-directional sockets between web browser and server –Avoid polling, long polling, Comet –HTML 5 (IE 10, Firefox 6+, Chrome 14+) –System.Web.WebSockets Performance improvements –Reduction in startup time and memory footprint
Web Forms Drag user controls in source view Extract user controls from web pages DataBinding with HTML Encoding – Strongly Typed Data Controls –ItemType
HTML 5 TextBox supports HTML 5 types –search – –url –tel –range – slider –number – spinner –date, datetime, time, month, week –color Not yet aware of new input attributes (placeholder, autofocus, required, pattern, etc)
Unobtrusive Validation Previously had large amount of JavaScript injected into HTML when used validators JavaScript moved to external script Uses “data-” attributes –Control attributes so accessible on client, such as data-val-display=“Dynamic“ for Display=“Dynamic” Not used by default, opt in via web.config –ValidationSettings:UnobtrusiveValidationMode PM> Install-Package Microsoft.ScriptManager.jQuery
Model Binding Model binding originally introduced with ASP.NET MVC, while integrating with existing Web Forms server controls Previously used DataSource controls or ObjectDataSource –Developers often want more control “Code focused approach to data-binding” –Create methods for data access –Server controls will use methods at appropriate times
Model Binding (2) SelectMethod, UpdateMethod, DeleteMethod Filtering via “Value Provider Attributes” –querystring, cookies, form values, controls, viewstate, session, or profile Model Validation –Create a new partial class –System.ComponentModel.DataAnnotations – – ShowModelStateErrors –ModelState.IsValid
Web Essentials 2012 Mads Kristensen (Microsoft) Add vendor prefixes Show browser support Data URI conversion (fallback support) Insert hacks for specific IE versions Colors conversions CoffeeScript and LESS support JavaScript regions
Resources Scott Guthrie’s ASP.NET 4.5 Blog Series – Visual Studio 11 Developer Preview Training Kit –
Thank blogs.aspadvice.com/robertb Robert Boedigheimer