Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
www.twitter.com/Telerik
www.facebook.com/Telerik
Philip Japikse (@skimedic)
www.skimedic.com/blog
MVP, MCSD.Net, MCDBA, CSM, CSP
Agile Practices Evangelist, Telerik
CONTROLLING ASP.NET MVC 4
WHO AM I?
8/30/2012 2
• 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
CONFIGURATION CHANGES
4/19/2008 3
APP_START
4/19/2008 4
• New folder holds:
• AuthConfig
• BundleConfig
• FilterConfig
• RouteConfig
• WebApiConfig
GLOBAL.ASAX CHANGES
4/19/2008 5
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(); }
DEMO –
CONFIGURATION CHANGES
4/19/2008 6
UPDATED TEMPLATES
• 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
ASP.NET MVC STARTER PROJECTS
8
STARTER SITES
9
RICHER UI
10
MVC TEMPLATES IN RTM…
• MVC templates are changed!
• No longer have responsive UI
• @media only screen and (max-width: 850px) { .. }
• NOTE: @media is a CSS3 element rendered by the browser, not a MVC4 specific item
ADAPTIVE RENDERING – MEDIA
QUERIES
12
DEMO –
IMPROVED TEMPLATES
MOBILE
HTML5 - IN THE BOX <ul data-role="listview" data-inset="true"> <li data-role="list-divider">Navigation</li> <li>@Html.ActionLink("Home", "Index", "Home")</li> <li>@Html.ActionLink("Contact", "Contact", "Home")</li> </ul>
VIEWPORT META TAG
<meta name="viewport" content="width=device-width" />
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<ActionResult>
• Support for Timeouts
• Add CancellationToken parameter
ASYNC CONTROLLERS public class HomeController : AsyncController { public async Task<ActionResult> 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<List<Photo>>(
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
4/19/2008 31
• 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
BREAKING CHANGES
4/19/2008 32
• Removed from Razor
• ModelSpan, Mvc<Language>RazorCodeGenerator,
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
CONTACT ME
8/30/2012 33
• www.skimedic.com/blog
• www.twitter.com/skimedic
• www.telerik.com/zerotoagile