CONTROLLING ASP.NET MVC 4

8 downloads 141 Views 823KB Size Report
Aug 30, 2012 ... www.skimedic.com/blog. MVP, MCSD.Net, MCDBA, CSM, CSP. Agile Practices Evangelist, Telerik. CONTROLLING ASP.NET MVC 4 ...
www.twitter.com/Telerik www.facebook.com/Telerik

CONTROLLING ASP.NET MVC 4 Philip Japikse (@skimedic)

[email protected] www.skimedic.com/blog MVP, MCSD.Net, MCDBA, CSM, CSP Agile Practices Evangelist, Telerik

WHO AM I? • Agile Practices Evangelist, Telerik, Inc.

• Microsoft MVP, MCSD, MCDBA, CSM, CSP • Lead Director, Cincinnati .NET User’s Group

• Founder, Agile Conferences, Inc. • Host, Zero To Agile Podcast

• www.telerik.com/zerotoagile

8/30/2012 2

CONFIGURATION CHANGES 4/19/2008

3

APP_START • New folder holds:

• AuthConfig • BundleConfig • FilterConfig • RouteConfig • WebApiConfig

4/19/2008

4

GLOBAL.ASAX CHANGES protected void Application_Start() { //area registration, etc WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); }

4/19/2008

5

DEMO – CONFIGURATION CHANGES 4/19/2008

6

UPDATED TEMPLATES

ASP.NET MVC STARTER PROJECTS • Intranet – • Starter website that uses forms authentication

• Internet – • Starter website that uses Windows authentication • Richer UI • Includes KnockoutJS, JQueryUI

• Mobile – • Optimized for Mobile Devices • Includes JQueryMobile

• WebAPI – • HTTP Service Application

8

STARTER SITES

9

RICHER UI

10

MVC TEMPLATES IN RTM… • MVC templates are changed!

• No longer have responsive UI

ADAPTIVE RENDERING – MEDIA QUERIES •

@media only screen and (max-width: 850px) { .. }



NOTE: @media is a CSS3 element rendered by the browser, not a MVC4 specific item

12

DEMO – IMPROVED TEMPLATES

MOBILE

HTML5 - IN THE BOX
  • Navigation
  • @Html.ActionLink("Home", "Index", "Home")
  • @Html.ActionLink("Contact", "Contact", "Home")


VIEWPORT META TAG

ADD JQUERY MVC TO INTERNET APPS • (NuGet) Install-Package jQuery.Mobile.MVC • Adds:

• _Layout.Mobile.cshtml • _ViewSwitcher.cshtml

• ViewSwitcherController.cs

VIEW SWITCHING

CREATING DISPLAY MODES DisplayModeProvider.Instance .Modes.Insert(0, new DefaultDisplayMode("iPhone") { ContextCondition = (context => context.GetOverriddenUserAgent() .IndexOf("iPhone", StringComparison.OrdinalIgnoreCase) >= 0) });

DEMO – DISPLAY MODES, VIEW SWITCHING, BROWSER OVERRIDING

ASYNC

TASK SUPPORT - ASYNC CONTROLLERS • Async action methods

• Written as single methods • Return Task or Task • Support for Timeouts • Add CancellationToken parameter

ASYNC CONTROLLERS public class HomeController : AsyncController { public async Task Index() { var client = new HttpClient(); var response = await client.GetAsync( Url.Action("gallery", "photo", null, Request.Url.Scheme)); var jss = new JavaScriptSerializer(); var result = jss.Deserialize( await response.Content.ReadAsStringAsync()); return View(result); }

}

HANDLING TIMEOUTS [AsyncTimeout(5000)] [HandleError(ExceptionType = typeof(TaskCanceledException), View = "TimedOut")]

DEMO – ASYNC

WEBAPI

ASP.NET WEB API • • • • • • • • • •

Modern HTTP Programming Model Routing Content Negotiation Model Binding and Validation Filters Query Composition Improved Testability Improved Inversion of Control Code-Based configuration Self-Hostable

DEMO – WEBAPI

ADD WEBAPI CONTROLLER • Derives from API Controller

WHAT’S NOT IN MVC4 (YET) • ASP.NET Single Page Application (postponed)

• SignalR (postponed) • Run Recipe – Removed from VS

UPGRADING MVC3 PROJECTS • Create new MVC4 Project • Copy Views, Controllers, Code, Content • Update all web config files • System.Web.MVC -> Version 4

• System.Web.WebPages -> Version 2 • System.Web.Helpers -> Version 2

• System.Web.WebPages.Razor -> Version 2 • Follow: • http://www.asp.net/whitepapers/mvc4-release-notes

4/19/2008

31

BREAKING CHANGES • Removed from Razor

• ModelSpan, MvcRazorCodeGenerator, MvcVBRazorCodeParser • WebMatrix takes over URL for Forms Auth • Breaks MVC RTM applications • Requires MVC3 Tools Update or • Manual updates from http://www.asp.net/whitepapers/mvc4-release-notes

4/19/2008

32

CONTACT ME • [email protected]

• www.skimedic.com/blog • www.twitter.com/skimedic • www.telerik.com/zerotoagile

8/30/2012 33