ASP.NET Overview - Alvin Lau

4,121
-1

Published on

1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total Views
4,121
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
108
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

ASP.NET Overview - Alvin Lau

  1. 1. ASP.NET 4+ OverviewAlvin LauSolutions Consultant, DatacraftMVP (ASP.NET/IIS) since Jul 2005SGDOTNET Council Membermicrolau@sgdotnet.org
  2. 2. ASP.NET 4+ OverviewAgenda• Advancements in ASP.NET 4.0• ASP.NET MVC 3.0• Questions and Answers
  3. 3. Advancements in ASP.NET 4.0
  4. 4. Advancements in ASP.NET 4.0Overview• Core Services• Ajax• Web forms• Dynamic Data• Web Application Deployment
  5. 5. Advancements in ASP.NET 4.0Core Services <?xml version="1.0"?> Web.config file refactoring <configuration> <system.web> <compilation targetFramework="4.0" /> </system.web> </configuration> Extensible Output Caching <caching> <outputCache defaultProvider="AspNetInternalProvider"> <providers> <add name=“DiskCache” type="Test.OutputCacheEx.DiskOutputCacheProvider, DiskCacheProvider"/> </providers> </outputCache> </caching> <%@ OutputCache Duration="60" VaryByParam="None" providerName="DiskCache" %> public override string GetOutputCacheProviderName(HttpContext context) { if (context.Request.Path.EndsWith("Advanced.aspx"))
  6. 6. Advancements in ASP.NET 4.0Core Services Auto-start (applicationHost.config) <applicationpools> <add name="MyApplicationPool" startMode="AlwaysRunning" /> </applicationpools> <sites> public name="MySite" id="1"> <site class CustomInitialization : System.Web.Hosting.IProcessHostPreloadClient <application path="/" { serviceAutoStartEnabled="true" public void Preload(string[] parameters) serviceAutoStartProvider="PrewarmMyCache" > { <!-- Additional content --> // Perform initialization. </application> } </site> } </sites> <!-- Additional content --> <serviceautostartproviders> <add name="PrewarmMyCache" type="MyNamespace.CustomInitialization, MyLibrary" /> </serviceautostartproviders>
  7. 7. Advancements in ASP.NET 4.0Core Services RedirectPermanent helper (Issue HTTP 301 Moved Permanently Response) Shrinking Session State (Using System.IO.Compression.GZipStream class) <sessionState mode="SqlServer" sqlConnectionString="data source=dbserver;Initial Catalog=aspnetstate" allowCustomSqlDatabase="true" compressionEnabled="true" />
  8. 8. Advancements in ASP.NET 4.0Core Services• Performance Monitoring (new performance counters) – % Managed Processor Time – Managed Memory Use Aspnet.config <?xml version="1.0" encoding="UTF-8" ?> <configuration> <runtime> <appDomainResourceMonitoring enabled="true"/> </runtime> </configuration>
  9. 9. Advancements in ASP.NET 4.0<%@ Page Language="C#" ... >Ajax<head runat="server"> Open-source jQuery</title> <title>Show Jquery</head> – jQuery-1.4.1.js<body> <form id="form1" runat="server"> – jQuery-1.4.1.min.js <div> – jQuery-1.4.1-vsdoc.js <asp:TextBox ID="txtFirstName"ID="sm1" EnableCdn="true" runat="server" <asp:ScriptManager runat="server" /> <script src="http://ajax.microsoft.com/ajax/jquery/jquery- CDN Support <br /> 1.4.2.js" type="text/javascript"></script> /> <asp:TextBox ID="txtLastName" runat="server" /> </div> Script Manager Explicit Scripts </form> <asp:ScriptManager ID="sm1" AjaxFrameworkMode="Explicit" <script src="Scripts/jquery-1.4.1.js" runat="server">type="text/javascript"></script> <Scripts> type="text/javascript"> <script <asp:ScriptReferencefunction() { $(this).css("background-color", $("input").focus( Name="MicrosoftAjaxCore.js" /> <asp:ScriptReference Name="MicrosoftAjaxComponentModel.js" />"yellow"); }); <asp:ScriptReference Name="MicrosoftAjaxSerialization.js" /> <asp:ScriptReference Name="MicrosoftAjaxNetwork.js" /> </script> </Scripts></body> </asp:ScriptManager></html>
  10. 10. Advancements in ASP.NET 4.0Web Forms Set meta tags <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Keywords="These, are, my, keywords" Description="This is a description" %> View State for Individual Controls  ViewStateMode (Enabled, Disabled, Inherit) <asp:PlaceHolder ID="PlaceHolder1" runat="server" <%@ Page Language="C#" AutoEventWireup="true" ViewStateMode="Disabled"> CodeBehind="Default.aspx.cs" <asp:PlaceHolder ID="PlaceHolder2" runat="server" Inherits="WebApplication1._Default" ViewStateMode="Enabled"> ViewStateMode="Disabled" %>
  11. 11. Advancements in ASP.NET 4.0Web Forms public class CustomProvider : HttpCapabilitiesEvaluator Browser Capabilities Providers {  Replacing ASP.NET Browser Capabilities public override HttpBrowserCapabilities 1. GetBrowserCapabilities(HttpRequest request) and overrides Create provider class from HttpCapabilitiesProvider { GetBrowserCapabilities method HttpBrowserCapabilities browserCaps = 2. Register provider with application base.GetHttpBrowserCapabilities(request); – if (browserCaps.Browser == "Unknown") browserCaps section in web.config or machine.config { – Write code in Application_Start (Global.asax) browserCaps = MyBrowserCapabilitiesEvaulator(request); } Caching HttpBrowserCapabilities Object (same process) return browserCaps;  Extending ASP.NET Browser Capabilities (same process) } }
  12. 12. Advancements in ASP.NET 4.0Web Forms Easier to useGlobal : System.Web.HttpApplication public class routing { protected void Page_Load(object sender, EventArgs e) <asp:sqldatasource id="SqlDataSource1" runat="server" {void Application_Start(object sender, EventArgs e)  PageRouteHandler class connectionstring="<%$ ConnectionStrings:MyNorthwind %>" { string searchterm = Page.RouteData.Values["searchterm"] as selectcommand="SELECT CompanyName,ShipperID FROM Shippers  New properties - HttpRequest.RequestContext, Page.RouteData string; RouteTable.Routes.MapPageRoute("SearchRoute", where label1.Text = builders - expression searchterm;  New "search/{searchterm}", "~/search.aspx"); CompanyName=@companyname" } RouteTable.Routes.MapPageRoute("UserRoute", System.Web.Compilation.RouteUrlExpressionBuilder, <selectparameters> "users/{username}", "~/users.aspx"); <asp:routeparameter name="companyname" RouteKey="searchterm" System.Web.Compilation.RouteValueExpressionBuilder http://localhost/search/scott } /> } RouteUrl  </selectparameters>  RouteValue RouteTable.Routes.Add("SearchRoute", new </asp:sqldatasource> <asp:HyperLink ID="HyperLink1" runat="server" Route("search/{searchterm}",  RouteParameter class NavigateUrl="<%$RouteUrl:SearchTerm=scott%>">Search for new PageRouteHandler("~/search.aspx"))); Scott</asp:HyperLink> http://localhost/search/scott
  13. 13. Advancements in ASP.NET 4.0Web Forms• <tc:NamingPanel runat="server" ID="ParentPanel" Setting Client IDs (ClientIDMode property) ClientIDMode="Static"> – AutoID (legacy) runat="server" ID="NamingPanel1" <tc:NamingPanel ClientIDMode="Predictable"> – Static <asp:TextBox ID="TextBox1" runat="server" – Predictable Text="Hello!"></asp:TextBox> </tc:NamingPanel> – Inherit </tc:NamingPanel> <%@ Page Language="C#" AutoEventWireup="true" <system.web> CodeFile="Default.aspx.cs" <pages clientIDMode="Predictable"></pages> Inherits="_Default" <div id="ParentPanel"> </system.web> ClientIDMode="Predictable" %> <div id="ParentPanel_NamingPanel1"> <input name="ctl00$ContentPlaceHolder1$ParentPanel$NamingPanel1$TextBox 1" type="text" value="Hello!" id="ParentPanel_NamingPanel1_TextBox1" /> </div>
  14. 14. Advancements in ASP.NET 4.0Web Forms ASP.NET Chart Controls
  15. 15. Advancements in ASP.NET 4.0Web Forms• QueryExtender Control <asp:LinqDataSource ID="dataSource" runat="server"> TableName="Products"> ID="dataSource" runat="server"> <asp:LinqDataSource TableName="Products"> ID="dataSource" runat="server" <asp:LinqDataSource </asp:LinqDataSource> TableName="Products"> ID="dataSource" runat="server" <asp:LinqDataSource </asp:LinqDataSource> <asp:QueryExtender TargetControlID="dataSource" runat="server"> TableName="Products"> </asp:LinqDataSource> <asp:QueryExtender TargetControlID="dataSource" runat="server"> <asp:SearchExpression DataFields="ProductName, </asp:LinqDataSource> <asp:QueryExtender TargetControlID="dataSource" runat="server"> <asp:RangeExpression DataField="UnitPrice" MinType="Inclusive" Supplier.CompanyName" TargetControlID="dataSource" runat="server"> <asp:QueryExtender <asp:PropertyExpression> MaxType="Inclusive"> SearchType="StartsWith"> <asp:CustomExpression OnQuerying="FilterProducts" /> <asp:ControlParameter ControlID="CheckBoxDiscontinued" <asp:ControlParameter ControlID="TextBoxSearch" /> <asp:ControlParameter ControlID="TextBoxFrom" /> </asp:QueryExtender> Name="Discontinued" /> </asp:SearchExpression> ControlID="TexBoxTo" /> <asp:ControlParameter </asp:PropertyExpression> </asp:RangeExpression> </asp:QueryExtender> protected void FilterProducts(object sender, </asp:QueryExtender> </asp:QueryExtender> CustomExpressionEventArgs e) { e.Query = from p in e.Query.Cast() where p.UnitPrice >= 10 select p; }
  16. 16. Advancements in ASP.NET 4.0Dynamic Data Enable on any ASP.NET application <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True" DataKeyNames="ProductID" DataSourceID="LinqDataSource1"> </asp:GridView> <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="DataClassesDataContext" EnableDelete="True" EnableInsert="True" EnableUpdate="True" TableName="Products"> </asp:LinqDataSource> GridView1.EnableDynamicData (typeof(Product)); DetailsView1.EnableDynamicData(typeof(Product), new { ProductName = "DefaultName" });
  17. 17. Enhancements with ASP.NET 4.0Web App Deployment Web Packaging Debug Web.config transformation Database deployment Testing Web.config Release One-click publish for web applications Staging
  18. 18. Advancements in ASP.Net 4.0Many more… Core Dynamic Web App Ajax Web Forms Services Data Deployment Extensible Request Declarative syntax Web Packaging Validation jQuery Persisting Row SelectionRange of allowable URLs Entity templates Web.config transformations Object caching CDN CSS Improvements New Field templates DB deployment Extensible HTML, URL, Creating links HTTP Header Encoding Rendering ScriptManager Improvements One-Click Publish Multi-targeting Support M:M (EF)
  19. 19. ASP.NET MVC 3.0
  20. 20. ASP.NET MVC 3.0Overview Razor View Engine Controller improvements Model validation improvements Nuget integration Partial page output caching Scaffolding improvements
  21. 21. ASP.NET MVC 3.0Razor View Engine New view engine (Razor syntax) Includes IntelliSense and color colorisation for Razor syntax Can be unit tested Includes HTML helpers  Chart, WebGrid, Crypto, WebImage, WebMail
  22. 22. Demo – Razor View Engine
  23. 23. ASP.NET MVC 3.0Controller Improvements Global Action Filters public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); filters.Add(new HandleLoggingAttribute()); } protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); }
  24. 24. ASP.NET MVC 3.0Controller Improvements “ViewBag” property public ActionResult Index() { ViewBag.Message = "Welcome to ASP.NET MVC!"; return View(); } “ActionResult” types  HttpNotFoundResult class – HTTP 404  HttpRedirectResult class has boolean “Permanent” property – HTTP 302 or HTTP 301 public ActionResult Test(int id) { return HttpNotFound(); }
  25. 25. ASP.NET MVC 3.0Controller Improvements JavaScript and Ajax improvements Client-side validation enabled by default Remote validator public class User { [Remote("UserNameAvailable", "Users")] public string UserName { get; set; } }
  26. 26. Demo – Remote Validator
  27. 27. ASP.NET MVC 3.0 Controller Improvements  JSON Binding support jQuery("#ajaxGrid").jqGrid({ url: @Url.Action("GridData"), datatype: "json", jsonReader: { repeatItems: false, id: "EventId" }, colNames: [EventId, EventName, EventDate, StartTime, EndTime,AllDay], colModel: [ { name: EventId, editable: true, sortable: false, hidden: true }, { name: EventName, editable: true, sortable: false, hidden: false }, { name: EventDate, editable: true, sortable: false, hidden: false }, { name: StartTime, editable: true, sortable: false, hidden: false }, { name: EndTime, editable: true, sortable: false, hidden: false }, { name: AllDay, editable: true, sortable: false, hidden: false }, ], rowNum: 3, pager: #ajaxGridPager, width: 850, height: 10.5em }),
  28. 28. ASP.NET MVC 3.0Model Validation Improvements “DataAnnotations” metadata attributes “ValidationAttribute” Class public class User { [Required] public string Password { get; set; } [Required, Compare("Password")] public string ComparePassword { get; set; } } Validation Interfaces  IValidatableObject, IClientValidatable interfaces Dependency Injection Improvements
  29. 29. ASP.NET MVC 3.0Other new features NuGet Integration Partial-Page Output Caching [OutputCache(Duration = 3600, VaryByParam = "id")] public ViewResult Details(int id) { return View(personRepository.GetById(id)); } Scaffolding Improvements
  30. 30. Resources Overview of ASP.NET 4 and VS 2010 Web Development http://www.asp.net/learn/whitepapers/aspnet4#0.2__Toc253429246 Unobstrusive JavaScript http://en.wikipedia.org/wiki/Unobtrusive_JavaScript ASP.NET MVC 3 http://www.asp.net/mvc/mvc3#overview http://msdn.microsoft.com/en-us/library/gg416514(v=VS.98).aspx ASP.NET MVC 3.0 Service Location (Dependency Injection) http://bradwilson.typepad.com/blog/2010/07/service-location-pt1-introduction.html Steven Sanderson’s Blog about MVC Scaffolding http://blog.stevensanderson.com/category/scaffolding/
  31. 31. Alvin LauSolutions Consultant,DatacraftMVP (ASP.NET/IIS)SGDOTNET Council Membermicrolau@sgdotnet.org
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×