Best Practices for ASP.NET Development Ammar Abuthuraya Developer & Platform Lead Microsoft Corporation.

Slides:



Advertisements
Similar presentations
Faith Allington Program Manager Microsoft Corporation WSV322.
Advertisements

Tahir Nawaz Introduction to.NET Framework. .NET – What Is It? Software platform Language neutral In other words:.NET is not a language (Runtime and a.
SSRS 2008 Architecture Improvements Scale-out SSRS 2008 Report Engine Scalability Improvements.
11 ASP.NET Slides based off:. 22 B ACKGROUND - W EB A RCHITECTURE Web Server PC/Mac/Unix/... + Browser Client Server Request:
ASP.NET (Active Server Page) SNU OOPSLA Lab. October 2005.
DEV392: Extending SharePoint Products And Technologies Through Web Parts And ASP.NET Clint Covington, Program Manager Data And Developer Services - Office.
XML Web Services in Visual Studio ®.NET NameTitleCompany.
Building Enterprise Applications Using Visual Studio ®.NET Enterprise Architect.
Technical Architectures
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 1.1 of…
Microsoft SharePoint 2013 SharePoint 2013 as a Developer Platform
Best Practices for Building Web Services with Visual Studio ®.NET Sanguan Thammarojsakul Microsoft MVP -.NET Department of Computer Science, Faculty of.
Microsoft ® ASP.NET: Designing and Developing a Line-of-Business Web Application.
Leveraging Application Blocks in Your Application Development Ihsan Anabtawi Technology Specialist Microsoft ® Corporation.
Microsoft ® Official Course Monitoring and Troubleshooting Custom SharePoint Solutions SharePoint Practice Microsoft SharePoint 2013.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
ASP.NET: Designing and Developing a Line-of-Business Web Application Ammar Abuthuraya Developer & Platform Lead Microsoft ® Corporation.
WEB329 ASP.NET: A Lap Around the New Enhancements for Web Developers in Microsoft Visual Studio 2005 Omar Khan Lead Program Manager Web Platform and Tools.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
Creating Business Workflow Using SharePoint Designer 2007 Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Microsoft SQL Server.
Best Practices for.NET Development Thom Robbins
© 2004 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Programming the Web Using ASP.Net Chapter 2: The ASP.Net Template Dave.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
A Scalable Application Architecture for composing News Portals on the Internet Serpil TOK, Zeki BAYRAM. Eastern MediterraneanUniversity Famagusta Famagusta.
CIS 375—Web App Dev II ASP.NET 2 Introducing Web Forms.
ASP.NET INTRODUCTION INTO وزارة التربية و التعليم العالي كلية العلوم و التكنولوجيا قسم علوم الحاسوب و تكنولوجيا المعلومات اعداد الاستاذ: عبد الله محمد.
Meir Botner David Ben-David. Project Goal Build a messenger that allows a customer to communicate with a service provider for a fee.
Introduction to .NET Rui Ye.
ASP.NET  ASP.NET is a web development platform, which provides a programming model, a comprehensive software infrastructure and various services required.
Joe Stagner Developer Community Champion Microsoft Corporation Best Practices and Techniques for Building Secure.
Visual Studio ®.NET Data with XML Carlotta Eaton ( Associate Professor of IST New River Community College Slides by Microsoft Modified.
Microsoft ®.NET and Microsoft ® Office 2003 Suthep Sangvirotjanaphat [MVP]
DEV302 Best Practices and Techniques for Web Performance Scott Guthrie ASP.NET Team.
Enticy GROUP THE A Framework for Web and WinForms (Client-Server) Applications “Enterprise Software Architecture”
ASP.NET Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital.
CS480 Computer Science Seminar Introduction to Microsoft Solutions Framework (MSF)
The Web Architecture and ASP.NET. Slide 2 Review of the Web (1) It began with HTTP and HTML, which delivers static Web pages to browsers which would render.
DEV325 Deploying Visual Studio.NET Applications Billy Hollis Author / Consultant.
Microsoft SharePoint Server 2010 for the Microsoft ASP.NET Developer Yaroslav Pentsarskyy
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
Introducing ASP.NET 2.0. Internet Technologies WWW Architecture Web Server Client Server Request Response Network HTTP TCP/IP PC/Mac/Unix + Browser (IE,
Create Windows ® Applications with.NET Carlotta Eaton ( Associate Professor of IST New River Community College Slides by Microsoft.
ASP.NET OPTIMIZATION. Why Optimize? $$$ Whether you build applications for customers or not, enhanced applications save money.
Active Server Pages (ASP), also known as Classic ASP or ASP Classic, was Microsoft's first server-side script engine for dynamically generated web pages.
VITALE, CATURANO & COMPANY LTD Microsoft SharePoint Web Part Development Overview VITALE, CATURANO & COMPANY LTD SharePoint Developer Series – Web Part.
PAGE DIRECTIVES. Page Directives  They are instructions, inserted at the top of an ASP.NET page, to control the behavior of ASP.NET pages.  So it is.
Introduction to ASP.NET COMPLETELY DESIGNED BY: COMPLETELY DESIGNED BY: ER.ASHISH PANDEY ER.ASHISH PANDEY (KNOWLEDGE EXECUTIVE ) (KNOWLEDGE EXECUTIVE )
ASP.NET in Definition: 1.ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites,
Building High Performance, Robust Server Applications with Internet Information Server 5.0 Van Van IIS - Program Manager Microsoft Corporation.
Web Services Error Handling and Debugging. Agenda Simple SOAP faults Advanced SOAP faults SOAP headers and faults Error handling From a Service Perspective.
ASP.NET (Active Server Page) SNU OOPSLA Lab. October 2005.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
ASP. NET Differences Dave Webster EMEA Technical Team dave
Migrating ASP to ASP.NET Matt Gibbs ASP.NET Development Manager.
Building Custom Controls with ASP.NET and the Microsoft ®.NET Framework Rames Gantanant Microsoft Regional Director, Thailand
Introduction to ASP.NET development. Background ASP released in 1996 ASP supported for a minimum 10 years from Windows 8 release ASP.Net 1.0 released.
Integrating and Extending Workflow 8 AA301 Carl Sykes Ed Heaney.
The best of WF 4.0 and AppFabric Damir Dobric MVP-Connected System Developer Microsoft Connected System Division Advisor Visual Studio Inner Circle member.
A Detailed Introduction To Visual Studio.NET CRB Tech ReviewsCRB Tech Reviews introduces you to the world of Visual.
Building Enterprise Applications Using Visual Studio®
ASP.NET Application Framework
Chapter 23 – ASP.NET Outline 23.1 Introduction NET Overview
Moving from ASP to ASP.NET
ASP.NET Module Subtitle.
ASP.NET 4.0 State Management Improvements – Deep Dive
DAT381 Team Development with SQL Server 2005
Serpil TOK, Zeki BAYRAM. Eastern MediterraneanUniversity Famagusta
Introduction to ASP.NET Parts 1 & 2
Mark Quirk Head of Technology Developer & Platform Group
Running C# in the browser
Presentation transcript:

Best Practices for ASP.NET Development Ammar Abuthuraya Developer & Platform Lead Microsoft Corporation

What we will cover  Designing ASP.NET Web forms  Use code-behind for best performance and scalability  ASP.NET caching techniques  State management options  Recommendations for communicating with COM components from ASP.NET

Session Prerequisites Level 300  Understand.NET architecture  Working knowledge of either VB.NET or C#  Knowledge of ASP.NET application architecture  Knowledge of ASP

So Why This Presentation?  You know how to build ASP applications and use the same techniques to build ASP.NET applications  You want to leverage the power and capabilities of ASP.NET  You want to use ASP.NET to build high- performance, scalable, web-based applications

Demonstrations  Language best practices  Server Control design practices  Component & user control design  State management recommendations  Caching techniques  Measuring performance

Agenda  Language and Code Practices  Server Control Design Practices  Component and User Control Usage Practices  State Management Recommendations  Deployment Best Practices  Measurement Techniques

Language and Code Practices Code Performance .NET Common Language Runtime (CLR) provides big runtime performance wins  Further optimize by native code generation using NGEN.EXE  No perf difference in.NET languages  Equivalent code written in VB and C# provides equivalent performance at runtime

Language and Code Practices Binding in VB.NET  Early binding in VB performs better than late binding ‘ VB Late Binding Example Dim j, obj obj = New System.Collections.ArrayList() for j = 0 To i obj.Add(j) obj.Add(j)Next ‘ VB Early Binding Example Dim j as integer, obj As ArrayList obj = New System.Collections.ArrayList() for j = 0 To i obj.Add(j) obj.Add(j)Next

Language and Code Practices Language Recommendations  Avoid using late binding in VB  Explicitly declare all variable types (Dim a as Long)  Avoid late bound methods on Object type  Use  Requires all variables to be declared (DIM required)  Still enables late bound code to exist though   Disallows any late bound code to be used

Language and Code Practices COM interop Issues  Apartment threaded components are particularly expensive in ASP.NET  ASP.NET now uses MTA thread pool by default that has very bad perf side effects when running STA components  This affects all VB6( STA) components!

Language and Code Practices interop Recommendations  Ideally migrate COM code to.NET  Alternatively structure APIs to be less “chatty” and more “chunky” in usage  Use COM interop through System.Runtime.interopServices  If using apartment components, mark page to run in STA compat mode: 

Language and Code Practices interop Recommendations  Be careful not to declare any STA component in “constructor” of page: Dim MyComponent as New MySTAComponent() 'Bad! Dim MyComponent as New MySTAComponent() 'Bad!</script> Dim MyComponent as MySTAComponent Dim MyComponent as MySTAComponent Sub Page_Load(Sender as Object, E as EventArgs) Sub Page_Load(Sender as Object, E as EventArgs) MyComponent = New MySTAComponent() MyComponent = New MySTAComponent() End Sub End Sub</script>

Demonstration 1 Language Best Practices Early binding vs. Late Binding Using COM objects in ASP.NET

Agenda  Language and Code Practices  Server Control Design Practices  Component and User Control Usage Practices  State Management Recommendations  Deployment Best Practices  Measurement Techniques

Server Control Design Practices Optimizing Server Control Rendering  Server controls provide a very clean programming model abstraction  Recommended way to build ASP.NET pages  Server controls do more rendering/postback work than old-style code  Should understand what this work is and optimize for it accordingly  Two areas to think about and optimize:  Rendering Content  ViewState Postback

Server Control Design Practices Optimizing Server Control Rendering  Server controls encapsulate rendering markup logic at runtime  Handle style and automatic uplevel/downlevel functionality management  individual server controls each add slight additional rendering cost  Additional allocations for style management  Additional allocations for control itself  Net take: the more individual server controls on page, the more this overhead can be noticed  Need to be especially aware of this w/ composite list controls that generate multiple controls per data row

Server Control Design Practices Optimizing Use of Viewstate  ASP.NET allows pages/controls to maintain state across round trips by storing state within hidden “viewstate” field  Disabled with “EnableViewState” attribute  Some downsides:  increases network payload  Performance overhead to serialize this  Recommendation:  Always review your usage of this feature  Always disable if you are not doing postback  Disable on per control basis if possible  Use to track usage size

Server Control Design Practices Data Validation Techniques  Leverage client side scripting capabilities to perform validations  Perform validation on both server & client side to avoid validation bypass  Make appropriate use of the RequiredFieldValidator  Use RegularExpressionValidator for validating complex field types like Credit Card

Server Control Design Practices Data Binding Best Practices  Multiple ways to do data access with.NET  SQL vs. OLEDB ADO.NET Provider  DataReaders vs. DataSets  Recommendations:  Always use SQL Data Provider for Microsoft ® SQL Server ™ data access  Use DataReaders for ASP.NET data access and use DataSets only when data caching or with web services

Demonstration 2 Server Control Design Practices Optimizing Server Control Rendering Optimizing Use of Viewstate Data Validation Best Practices Data Binding Best Practices

Agenda  Language and Code Practices  Server Control Design Practices  Component and User Control Usage Practices  State Management Recommendations  Deployment Best Practices  Measurement Techniques

Component & User Control Practices Improving User Experience  ASP.NET built-in caching features  Output Caching  Fragment Caching  Caches the static result of an ASP.NET page  Use the directive to control caching behavior

Component & User Control Practices Improving User Experience  Caching Options:  Duration - Time item exists in the cache  VaryByParam - Varies cache entries by Get/Post params. Name param, separate by semi-colons, supports *  VaryByHeader - Varies cache entries by Http header  VaryByCustom - Override method within Global.asax to custom vary by whatever you want (you control the cache key)

Component & User Control Practices Improving User Experience  Caching the entire page isn’t always possible  Partial page personalization, etc.  Fragment Caching allows caching regions of a page by using user controls (.ascx)  User controls define directive

Component & User Control Practices Coding Patterns in ASP.NET  Common coding patterns:  Spaghetti – include all presentation logic and code in the same page like classic ASP  Code behind – all presentation logic is in the aspx file, which is linked to a separate code behind file  Component – business logic is present in a compiled component, which is invoked for providing various services  There is no perf difference between a dynamically compiled.aspx (“spaghetti”) and “code behind” style page

Component & User Control Practices Optimizing Data Flow Across Tiers  Data exchange across tiers has to be optimized for the deployment scenario  Avoid passing datasets across tiers  Use DataReaders for fast, forward-only access to the data stream  XML is very verbose; suitable for communications with unknown systems

Component & User Control Practices Optimizing Data Flow Across Tiers  Minimize the number of post backs  Leverage client side capabilities to avoid post backs  Control the amount of view state information passed during a post back  Use EnableViewState at page or control level to configure view state usage.

Demonstration 3 Component & User Control Best Practices Buffered Output Fragment Caching & Custom Caching Code Behind, User Controls & Components Data Flow Across Tiers Optimizing Postback

Agenda  Language and Code Practices  Server Control Design Practices  Component and User Control Usage Practices  State Management Recommendations  Deployment Best Practices  Measurement Techniques

State Management Recommendations in Proc Session State  Session state is stored in the ASP.NET worker process  Recycling the process will cause all session state to be lost  Session state performance is maximum in this mode

State Management Recommendations Out of Proc Session State  Session state can be stored in a State server process running on the same machine or a different machine  State can also be stored in a SQL Server database  Restarting the web server does not cause the session state to be lost  More reliable than in process session state but less performant

State Management Recommendations Configuring Session State  Session state can be configured via the element in the web.config file  Change causes ASP.NET application to be restarted, all new sessions will be stored as per the updated session configuration  Out of process session state stores like State Server or SQL Server must be started & configured properly

Demonstration 4 State Management Best Practices State Management Session State in A State Server

Agenda  Language and Code Practices  Server Control Design Practices  Component and User Control Usage Practices  State Management Recommendations  Deployment Best Practices  Measurement Techniques

Deployment Best Practices Logical Design  Design your applications using logical 3-Tier Design Practices:  Pages (.aspx) and User Controls (.ascx)  Reusable Biz Classes in \bin dir (.vb +.cs)  Data within a SQL Database  Design your Web application so that it can be distributed across a Web farm  Your code shouldn’t assume that a client will always return to the same machine  Be careful of assumptions regarding statics and application state

Deployment Best Practices Physical Deployment  Deploy your applications such that the pages and components run in same process  Deploying onto remote servers connected via DCOM or Web Services will almost always hurt your performance/scalability  Leverage Web services only for application to application communication -- not intra app calls  Leverage ISA Server for configurations where a DMZ security zone is required  Enables you to restrict app server access from browser clients

Deployment Best Practices ISA for DMZ Configurations ISA ASP.NET SQL DMZ (firewalled) Browsers

Agenda  Language and Code Practices  Server Control Design Practices  Component and User Control Usage Practices  State Management Recommendations  Deployment Best Practices  Measurement Techniques

Measurement Techniques Overview of Application Center Test  Application Center Test (ACT) is a tool designed for stress testing web servers  The tool assists in determining performance and scalability of a given web site  The tool also collect useful statistical information during the stress test  ACT also exposes a programming interface, which can be used for creating stress test scripts

Measurement Techniques Key Performance indicators  The key performance indicators of a web application are:  Processor utilization  Low value indicates blocking on other resources  ASP.NET  Requests/Sec & Requests Queued  Memory  Pages Faults/Sec – lower the better, high numbers indicate insufficient memory condition

Measurement Techniques Stress Testing  Stress testing is a defensive mechanism to creating scalable web sites  Stress runs will indicate the scalability of the application  Can be used to determine scale of operation, when to add new hardware etc  Stress testing should not be the final step in building a web application. It should be integrated into the development life cycle  Narrow the scope of a stress run to get more accurate, actionable results

Measurement Techniques Stress Testing  Use the web site logs to determine operational load  Stress tools like WAS (“Homer”) allow log files to be “replayed” on a web site and record statistical performance information  Run performance monitoring tools on the live servers to identify scalability issues

Measurement Techniques Designing Scalable Applications  Two ways to quantify Web performance:  Machine Throughput (requests/sec)  Response Time (time to first/last bytes)  Measure performance by stressing server  Utilize multiple client stress machines  Use Application Center Test tool  Measure multiple scenarios:  Simulate end to end scenario walkthroughs of site  Measure individual page performances

Demonstration 5 Measurement Techniques Performance Measurement

Session Summary  in this session we discussed:  Language and Code Practices  Server Control Design Practices  Component and User Control Usage Practices  State Management Recommendations  Caching Techniques  Deployment Best Practices  Measurement Techniques

for More information…  MSDN Web site at  msdn.microsoft.com

Training & Events MSDN Webcasts, MSDN Online Seminars, Tech-Ed, PDC, Developer Days MSDN Essential Resources for Developers Subscription Services Online information Membership Programs Print Publications Library, OS, Professional, Enterprise, Universal Delivered via CD-ROM, DVD, Web MSDN Online, MSDN Flash, How-To Resources, Download Center MSDN User Groups MSDN Magazine MSDN News

How-To Resources Simple, Step-By-Step Procedures  Embedded Development How-To Resources  General How-To Resources  integration How-To Resources  JScript.NET How-To Resources .NET Development How-To Resources  office Development Resources  Security How-To Resources  Visual Basic ®.NET How-To Resources  Visual C# ®.NET How-To Resources  Visual Studio ®.NET How-To Resources  Web Development How-To Resources (ASP, IIS, XML)  Web Services How-To Resources  Windows ® Development How-To Resources

MSDN Webcasts interactive, Live Online Event  interactive, Synchronous, Live Online Event  Discuss the Hottest Topics from Microsoft  Open and Free for The General Public  Takes Place Every Tuesdays

MSDN Subscriptions THE way to get Visual Studio.NET Visual Studio.NET MSDN Subscriptions NEW Professional Tools to build applications and XML Web services for Windows and the WebTools to build applications and XML Web services for Windows and the Web MSDN Professional $1199 new $899 renewal/upgrade MSDN Enterprise $2199 new $1599 renewal/upgrade MSDN Universal $2799 new $2299 renewal/upgrade Enterprise Developer Enterprise lifecycle toolsEnterprise lifecycle tools Team development supportTeam development support Core.NET Enterprise ServersCore.NET Enterprise Servers Enterprise Architect Software and data modelingSoftware and data modeling Enterprise templatesEnterprise templates Architectural guidanceArchitectural guidance

Where Can I Get MSDN?  Visit MSDN Online at msdn.microsoft.com  Register for the MSDN Flash Newsletter at msdn.microsoft.com/flash  Become an MSDN CD Subscriber at msdn.microsoft.com/subscriptions  MSDN online seminars msdn.microsoft.com/training/seminars  Attend More MSDN Events

MS Press Essential Resources for Developers Microsoft® Visual Studio®.NET is here! This is your chance to start building the next big thing. Develop your.NET skills, increase your productivity with.NET Books from Microsoft Press®

Training Training Resources for Developers  Course Title: introduction to Microsoft ASP.NET  Course Number:2063  Availability: Now  Detailed Syllabus: To locate a training provider for this course, please access Microsoft Certified Technical Education Centers are Microsoft’s premier partners for training services

Become A Microsoft Certified Solution Developer  What is MCSD?  Microsoft Certified Solution Developer  The premier certification for lead developers who design and develop leading-edge enterprise solutions with Microsoft development tools, technologies, and the Microsoft.NET Framework.  How do I attain the MCSD for Microsoft.NET certification?  4 core exams  1 elective exam  For complete information visit: