SlideShare a Scribd company logo
ASP.NET 4+ Overview

Alvin Lau
Solutions Consultant, Datacraft
MVP (ASP.NET/IIS) since Jul 2005
SGDOTNET Council Member
microlau@sgdotnet.org
ASP.NET 4+ Overview
Agenda

•   Advancements in ASP.NET 4.0
•   ASP.NET MVC 3.0
•   Questions and Answers
Advancements in ASP.NET 4.0
Advancements in ASP.NET 4.0
Overview

•   Core Services
•   Ajax
•   Web forms
•   Dynamic Data
•   Web Application Deployment
Advancements in ASP.NET 4.0
Core 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"))
Advancements in ASP.NET 4.0
Core 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>
Advancements in ASP.NET 4.0
Core 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"
    />
Advancements in ASP.NET 4.0
Core 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>
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>
Advancements in ASP.NET 4.0
Web 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" %>
Advancements in ASP.NET 4.0
Web 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)
      }
    }
Advancements in ASP.NET 4.0
Web 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
Advancements in ASP.NET 4.0
Web 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>
Advancements in ASP.NET 4.0
Web Forms

   ASP.NET Chart Controls
Advancements in ASP.NET 4.0
Web 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;
         }
Advancements in ASP.NET 4.0
Dynamic 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" });
Enhancements with ASP.NET 4.0
Web App Deployment

   Web Packaging                                      Debug

   Web.config transformation
   Database deployment
                                             Testing   Web.config   Release
   One-click publish for web applications



                                                       Staging
Advancements in ASP.Net 4.0
Many more…


   Core                                                              Dynamic                Web App
                            Ajax          Web Forms
  Services                                                            Data                 Deployment
  Extensible Request
                                                                      Declarative syntax     Web Packaging
      Validation
                             jQuery       Persisting Row Selection

Range 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)
ASP.NET MVC 3.0
ASP.NET MVC 3.0
Overview

   Razor View Engine
   Controller improvements
   Model validation improvements
   Nuget integration
   Partial page output caching
   Scaffolding improvements
ASP.NET MVC 3.0
Razor 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
Demo – Razor View Engine
ASP.NET MVC 3.0
Controller 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);
    }
ASP.NET MVC 3.0
Controller 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();
    }
ASP.NET MVC 3.0
Controller Improvements

   JavaScript and Ajax improvements
   Client-side validation enabled by default
   Remote validator
    public class User
    {
        [Remote("UserNameAvailable", "Users")]
        public string UserName { get; set; }
    }
Demo – Remote Validator
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'
    }),
ASP.NET MVC 3.0
Model 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
ASP.NET MVC 3.0
Other 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
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/
Alvin Lau
Solutions Consultant,
Datacraft
MVP (ASP.NET/IIS)
SGDOTNET Council Member
microlau@sgdotnet.org

More Related Content

What's hot (20)

PPTX
Walther Aspnet4
rsnarayanan
 
PPTX
Walther Ajax4
rsnarayanan
 
PPTX
Ajax control asp.net
Sireesh K
 
PPTX
ASP.NET Lecture 1
Julie Iskander
 
PPTX
Ajax and ASP.NET AJAX
Julie Iskander
 
PPT
Asp.net server controls
Raed Aldahdooh
 
PPT
ASP.NET AJAX with Visual Studio 2008
Caleb Jenkins
 
PPTX
05.SharePointCSOM
EaswariSP
 
PPTX
Harish Aspnet Deployment
rsnarayanan
 
PPTX
ASP .NET MVC
eldorina
 
PPSX
Asp.net mvc
Er. Kamal Bhusal
 
PDF
Asp .net web form fundamentals
Gopal Ji Singh
 
PPTX
Asp.net mvc presentation by Nitin Sawant
Nitin S
 
PPT
Asp.Net Ajax Component Development
Chui-Wen Chiu
 
PPTX
ASP.NET MVC and ajax
Brij Mishra
 
PPT
Asp.net.
Naveen Sihag
 
PDF
Asp dot net final (2)
Amelina Ahmeti
 
PPTX
Advanced SharePoint Web Part Development
Rob Windsor
 
PPTX
ASP.NET MVC Performance
rudib
 
Walther Aspnet4
rsnarayanan
 
Walther Ajax4
rsnarayanan
 
Ajax control asp.net
Sireesh K
 
ASP.NET Lecture 1
Julie Iskander
 
Ajax and ASP.NET AJAX
Julie Iskander
 
Asp.net server controls
Raed Aldahdooh
 
ASP.NET AJAX with Visual Studio 2008
Caleb Jenkins
 
05.SharePointCSOM
EaswariSP
 
Harish Aspnet Deployment
rsnarayanan
 
ASP .NET MVC
eldorina
 
Asp.net mvc
Er. Kamal Bhusal
 
Asp .net web form fundamentals
Gopal Ji Singh
 
Asp.net mvc presentation by Nitin Sawant
Nitin S
 
Asp.Net Ajax Component Development
Chui-Wen Chiu
 
ASP.NET MVC and ajax
Brij Mishra
 
Asp.net.
Naveen Sihag
 
Asp dot net final (2)
Amelina Ahmeti
 
Advanced SharePoint Web Part Development
Rob Windsor
 
ASP.NET MVC Performance
rudib
 

Viewers also liked (6)

PPT
Cozimento do Caldo
Luciane Figueira
 
PPT
Escaparate.
clarividente
 
PPT
Encuesta De SatisfacciÓn De LogÍstica
logisticaofficenet
 
PPS
The Window
Nafass
 
PPS
Persian New Year
Nafass
 
PPS
Learn to live
Nafass
 
Cozimento do Caldo
Luciane Figueira
 
Escaparate.
clarividente
 
Encuesta De SatisfacciÓn De LogÍstica
logisticaofficenet
 
The Window
Nafass
 
Persian New Year
Nafass
 
Learn to live
Nafass
 
Ad

Similar to ASP.NET Overview - Alvin Lau (20)

PPTX
Whats new in ASP.NET 4.0
py_sunil
 
PPT
ASP.NET 4.0 Demo
Abhishek Sur
 
PPTX
Visual Studio2010
HimaVejella
 
PPT
ASPNET Roadmap
ukdpe
 
PPTX
Aspnet 4 new features
Erkan BALABAN
 
PPT
Microsoft Tech Ed 2006 #1
Jetsada Phantharangsee
 
PPTX
A Web Developer's Journey across different versions of ASP.NET
Harish Ranganathan
 
PPT
Aspnet40 session final-1
Abhishek Sur
 
PDF
ASP.NET Scalability - NxtGen Oxford
Phil Pursglove
 
PPT
New Features Of ASP.Net 4 0
Dima Maleev
 
PDF
ASP.NET Scalability - DDD7
Phil Pursglove
 
PPT
Net Framework Hima
HimaVejella
 
PPTX
Being a tweaker modern web performance techniques
Chris Love
 
PPTX
Vs2010 Aspnet MSP Bootcamp_MVP Ngan Seok Chern
Quek Lilian
 
PPSX
06 asp.net session08
Vivek Singh Chandel
 
PPT
.Net Project Portfolio for Roger Loving
rloving10
 
PDF
Vs2010 Apiit Mix On Campus_Ngan Seok Chern
Quek Lilian
 
PPTX
What’s New in ASP.NET 4
Todd Anglin
 
PPTX
2009 - Basta!: Url rewriting mit iis, asp.net und routing engine
Daniel Fisher
 
PPTX
Development In ASP.NET by Tanzim Saqib
guestf8f959
 
Whats new in ASP.NET 4.0
py_sunil
 
ASP.NET 4.0 Demo
Abhishek Sur
 
Visual Studio2010
HimaVejella
 
ASPNET Roadmap
ukdpe
 
Aspnet 4 new features
Erkan BALABAN
 
Microsoft Tech Ed 2006 #1
Jetsada Phantharangsee
 
A Web Developer's Journey across different versions of ASP.NET
Harish Ranganathan
 
Aspnet40 session final-1
Abhishek Sur
 
ASP.NET Scalability - NxtGen Oxford
Phil Pursglove
 
New Features Of ASP.Net 4 0
Dima Maleev
 
ASP.NET Scalability - DDD7
Phil Pursglove
 
Net Framework Hima
HimaVejella
 
Being a tweaker modern web performance techniques
Chris Love
 
Vs2010 Aspnet MSP Bootcamp_MVP Ngan Seok Chern
Quek Lilian
 
06 asp.net session08
Vivek Singh Chandel
 
.Net Project Portfolio for Roger Loving
rloving10
 
Vs2010 Apiit Mix On Campus_Ngan Seok Chern
Quek Lilian
 
What’s New in ASP.NET 4
Todd Anglin
 
2009 - Basta!: Url rewriting mit iis, asp.net und routing engine
Daniel Fisher
 
Development In ASP.NET by Tanzim Saqib
guestf8f959
 
Ad

More from Spiffy (20)

PDF
01 server manager spiffy
Spiffy
 
PDF
Active Directory Upgrade
Spiffy
 
PDF
Checking the health of your active directory enviornment
Spiffy
 
PPTX
Agile in Action - Act 2: Development
Spiffy
 
PDF
Agile in Action - Act 3: Testing
Spiffy
 
PPTX
Agile in Action - Keynote: Becoming and Being Agile - What Does This Mean?
Spiffy
 
PPTX
Agile in Action - Act 1 (Set Up, Planning, Requirements and Architecture)
Spiffy
 
PDF
MS TechDays 2011 - WCF Web APis There's a URI for That
Spiffy
 
PDF
MS TechDays 2011 - NUI, Gooey and Louie
Spiffy
 
PDF
MS TechDays 2011 - Mango, Mango! Developing for Windows Phone 7
Spiffy
 
PDF
MS TechDays 2011 - Generate Revenue on Azure
Spiffy
 
PDF
MS TechDays 2011 - HTML 5 All the Awesome Bits
Spiffy
 
PDF
MS TechDays 2011 - Cloud Computing with the Windows Azure Platform
Spiffy
 
PDF
MS TechDays 2011 - Simplified Converged Infrastructure Solutions
Spiffy
 
PDF
MS TechDays 2011 - SCDPM 2012 The New Feature of Data Protection
Spiffy
 
PDF
MS TechDays 2011 - Microsoft Exchange Server and Office 365 Hybrid Deployment
Spiffy
 
PDF
MS TechDays 2011 - How to Run Middleware in the Cloud Story of Windows Azure ...
Spiffy
 
PDF
MS TechDays 2011 - Cloud Management with System Center Application Controller
Spiffy
 
PDF
MS TechDays 2011 - Virtualization Solutions to Optimize Performance
Spiffy
 
PDF
MS TechDays 2011 - Automating Your Infrastructure System Center Orchestrator ...
Spiffy
 
01 server manager spiffy
Spiffy
 
Active Directory Upgrade
Spiffy
 
Checking the health of your active directory enviornment
Spiffy
 
Agile in Action - Act 2: Development
Spiffy
 
Agile in Action - Act 3: Testing
Spiffy
 
Agile in Action - Keynote: Becoming and Being Agile - What Does This Mean?
Spiffy
 
Agile in Action - Act 1 (Set Up, Planning, Requirements and Architecture)
Spiffy
 
MS TechDays 2011 - WCF Web APis There's a URI for That
Spiffy
 
MS TechDays 2011 - NUI, Gooey and Louie
Spiffy
 
MS TechDays 2011 - Mango, Mango! Developing for Windows Phone 7
Spiffy
 
MS TechDays 2011 - Generate Revenue on Azure
Spiffy
 
MS TechDays 2011 - HTML 5 All the Awesome Bits
Spiffy
 
MS TechDays 2011 - Cloud Computing with the Windows Azure Platform
Spiffy
 
MS TechDays 2011 - Simplified Converged Infrastructure Solutions
Spiffy
 
MS TechDays 2011 - SCDPM 2012 The New Feature of Data Protection
Spiffy
 
MS TechDays 2011 - Microsoft Exchange Server and Office 365 Hybrid Deployment
Spiffy
 
MS TechDays 2011 - How to Run Middleware in the Cloud Story of Windows Azure ...
Spiffy
 
MS TechDays 2011 - Cloud Management with System Center Application Controller
Spiffy
 
MS TechDays 2011 - Virtualization Solutions to Optimize Performance
Spiffy
 
MS TechDays 2011 - Automating Your Infrastructure System Center Orchestrator ...
Spiffy
 

ASP.NET Overview - Alvin Lau

  • 1. ASP.NET 4+ Overview Alvin Lau Solutions Consultant, Datacraft MVP (ASP.NET/IIS) since Jul 2005 SGDOTNET Council Member [email protected]
  • 2. ASP.NET 4+ Overview Agenda • Advancements in ASP.NET 4.0 • ASP.NET MVC 3.0 • Questions and Answers
  • 4. Advancements in ASP.NET 4.0 Overview • Core Services • Ajax • Web forms • Dynamic Data • Web Application Deployment
  • 5. Advancements in ASP.NET 4.0 Core 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. Advancements in ASP.NET 4.0 Core 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. Advancements in ASP.NET 4.0 Core 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. Advancements in ASP.NET 4.0 Core 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. 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. Advancements in ASP.NET 4.0 Web 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. Advancements in ASP.NET 4.0 Web 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. Advancements in ASP.NET 4.0 Web 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. Advancements in ASP.NET 4.0 Web 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. Advancements in ASP.NET 4.0 Web Forms  ASP.NET Chart Controls
  • 15. Advancements in ASP.NET 4.0 Web 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. Advancements in ASP.NET 4.0 Dynamic 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. Enhancements with ASP.NET 4.0 Web App Deployment  Web Packaging Debug  Web.config transformation  Database deployment Testing Web.config Release  One-click publish for web applications Staging
  • 18. Advancements in ASP.Net 4.0 Many more… Core Dynamic Web App Ajax Web Forms Services Data Deployment Extensible Request Declarative syntax Web Packaging Validation jQuery Persisting Row Selection Range 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)
  • 20. ASP.NET MVC 3.0 Overview  Razor View Engine  Controller improvements  Model validation improvements  Nuget integration  Partial page output caching  Scaffolding improvements
  • 21. ASP.NET MVC 3.0 Razor 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. Demo – Razor View Engine
  • 23. ASP.NET MVC 3.0 Controller 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. ASP.NET MVC 3.0 Controller 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. ASP.NET MVC 3.0 Controller 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. Demo – Remote Validator
  • 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. ASP.NET MVC 3.0 Model 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. ASP.NET MVC 3.0 Other 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. 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. Alvin Lau Solutions Consultant, Datacraft MVP (ASP.NET/IIS) SGDOTNET Council Member [email protected]