Best Practices for.NET Development Thom Robbins

Slides:



Advertisements
Similar presentations
How to Build Multi- threaded Applications in.NET Mazen S. Alzogbi Technology Specialist Microsoft Corporation.
Advertisements

Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.
Visual Basic.NET A look into the.NET Programming Model Bryan Jenks Integrated Ideas ©2005.
Tiger Computer Services Ltd Using Interfaces in.NET Simplifying access to multiple DB providers in.NET Liam
XML Web Services in Visual Studio ®.NET NameTitleCompany.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
It’s always better live. MSDN Events Security Best Practices Part 2 of 2 Reducing Vulnerabilities using Visual Studio 2008.
490dp Synchronous vs. Asynchronous Invocation Robert Grimm.
Using Visual Basic 6.0 to Create Web-Based Database Applications
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
ASP.NET Programming with C# and SQL Server First Edition
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Jonas Thomsen, Ph.d. student Computer Science University of Aarhus Best Practices and Techniques for Building Secure Microsoft.
Best Practices for Building Web Services with Visual Studio ®.NET Sanguan Thammarojsakul Microsoft MVP -.NET Department of Computer Science, Faculty of.
Leveraging Application Blocks in Your Application Development Ihsan Anabtawi Technology Specialist Microsoft ® Corporation.
Visual Basic.NET A look into the.NET Programming Model Bryan Jenks Integrated Ideas ©2005.
Ins and Outs of Authenticating Users Requests to IIS 6.0 and ASP.NET Chris Adams Program Manager IIS Product Unit Microsoft Corporation.
Modern Concurrency Abstractions for C# by Nick Benton, Luca Cardelli & C´EDRIC FOURNET Microsoft Research.
Overview of SQL Server Alka Arora.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
VS.NET Syllabus By Peter Huang.
Meir Botner David Ben-David. Project Goal Build a messenger that allows a customer to communicate with a service provider for a fee.
Visual Studio ®.NET Data with XML Carlotta Eaton ( Associate Professor of IST New River Community College Slides by Microsoft Modified.
Creating Databases for Web Applications Work session Open Source versus Proprietary important topics HW: finish* projects. Look at final quiz guide. Final.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
Using Visual Basic 6.0 to Create Web-Based Database Applications
Computer Measurement Group, India Optimal Design Principles for better Performance of Next generation Systems Balachandar Gurusamy,
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Security Planning and Administrative Delegation Lesson 6.
2. Introduction to the Visual Studio.NET IDE. Chapter Outline Overview of the Visual Studio.NET IDE Overview of the Visual Studio.NET IDE Menu Bar and.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
DEV325 Deploying Visual Studio.NET Applications Billy Hollis Author / Consultant.
SQL Server User Group Meeting Reporting Services Tips & Tricks Presented by Jason Buck of Custom Business Solutions.
Moving from Microsoft ® ADO 2.X To ADO.NET Jackie Goldstein Renaissance Computer Systems Ltd. MSDN Regional Director, Israel Prerequisites.
tom perkins1 XML Web Services -.NET FRAMEWORK – Part 1 CHAPTER 1.1 – 1.3.
Securing Your ASP.NET Application Presented by: Rob Bagby Developer Evangelist Microsoft ( )
From DNA to.NET Design Path. Objectives Sketch up a typical Win DNA Application Sketch up the.NET version Compare Design and Implementation Advantages.
Presented By: Ahmed ALSUM PhD Student CS 895:.Net Security Old Dominion University College of Science Department of Computer Science.
Ins and Outs of Authenticating Users Requests to IIS 6.0 and ASP.NET Chris Adams Program Manager IIS Product Unit Microsoft Corporation.
ASP.Net Role-based Security Chapter 10 (Freeman and Jones) CS795/895.
Web Services Error Handling and Debugging. Agenda Simple SOAP faults Advanced SOAP faults SOAP headers and faults Error handling From a Service Perspective.
DAT430 Extending Microsoft ® ADO.NET Building a Custom Data Factory API DAT430 Extending Microsoft ® ADO.NET Building a Custom Data Factory API Gert E.R.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
1.Net Framework.Net Framework.NET Architecture and Security By Prasad Sundararajan Jan
Slide 1. Agenda  Introduction to Windows Workflow What is it? What are activities? Hosting  Out of the box Activities  Custom Activities and Dependency.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
.NET Mobile Application Development XML Web Services.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI.
Unit 7 ITT TECHNICAL INSTITUTE NT1330 Client-Server Networking II Date: 2/3/2016 Instructor: Williams Obinkyereh.
ASP.NET 2.0 Security Alex Mackman CM Group Ltd
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
ASP.NET Programming with C# and SQL Server First Edition
SE-1021 Software Engineering II
/* LIFE RUNS ON CODE*/ Konstantinos Pantos Microsoft MVP ASP.NET
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2014
z/Ware 2.0 Technical Overview
Chris Menegay Sr. Consultant TECHSYS Business Solutions
Server Concepts Dr. Charles W. Kann.
Writing Highly Available .Net Framework Applications
Security mechanisms and vulnerabilities in .NET
ASP.NET Module Subtitle.
Saranya Sriram Developer Evangelist | Microsoft
How to organize and document your classes
A look into the .NET Programming Model
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2018
Presentation transcript:

Best Practices for.NET Development Thom Robbins

What we will cover  Design Guidelines  Memory Management  Data Access  Internet Services  Threading  Security

Session Prerequisites  Know VB.NET or C#  Be familiar with.NET Base Class Libraries  Be familiar with XML Level 300

So Why This Presentation?  You know you are a VB programmer if…  You ever had to use the On Error Goto statement  You never wrote a multi-threaded app  You know you are a C++ programmer if…  You ever had to check an HRESULT every 2 lines of code  30% of your code was releasing objects from memory  You know you are an ADO programmer if…  You had to convert between a Recordset and a DOM and transform the XML 5 times in between

Agenda .NET Design Guidelines  Memory Management  Data Access  Internet Services  Threading  Security

.NET Design Guidelines Naming Conventions  Hungarian notation is out!  For public interfaces, use PascalCasing  For private members, use camelCasing  Use underscore “_” character to denote private class members  Use camelCasing for all method parameters

.NET Design Guidelines Naming Conventions public class Customer { private string _password; public void SetPassword(string newPassword) { _password = newPassword; }

.NET Design Guidelines Class Members Usage  Don’t use public fields, use properties  No write-only methods, use a method  Only use properties for setting and retrieving values  Allow properties to be set in any order  Use a consistent ordering and naming pattern for parameters

.NET Design Guidelines Base Classes vs. Interfaces  Only Use Interfaces When…  Unrelated classes want to support a protocol  Aggregation is not appropriate  Provide class customization through protected methods

.NET Design Guidelines Error Raising and Handling  Exceptions are not for flow of control!  Exceptions are “exceptional”  Derive new custom exceptions from the ApplicationException class

Agenda .NET Design Guidelines  Memory Management  Data Access  Internet Services  Threading  Security

Memory Management  Avoid Finalize()  Only use Finalize() with Dispose() public void Dispose() { // Clean up unmanaged resources GC.SuppressFinalize(this); } protected override void Finalize() { // Clean up unmanaged resources base.Finalize(); }

Agenda .NET Design Guidelines  Memory Management  Data Access  Internet Services  Threading  Security

Data Access Accessing Relational Data  Always use the optimal Managed Provider  Pick DataReader over DataSet when possible  Used stored procedures when possible  Do NOT use dynamic connection strings

Data Access XML Data  Use the XmlDataDocument for XML/DataSet integration  DOM  DataSet  DOM  Don’t use DOM if you don’t need it  Only necessary for in-memory editing  XmlReader is faster than DOM

Agenda .NET Design Guidelines  Memory Management  Data Access  Internet Services  Threading  Security

Internet Services WebClient vs. WebRequest  Use WebClient for simple request and response operations  Use WebRequest for more complex operations  Asynchronous requests, setting headers, etc.

Internet Services General Tips  Don’t pass credentials every time  Don’t type cast to descendant classes, such as HttpRequest  In ASP.NET, use the asynchronous methods of GetResponse and GetResponseStream  As a good starting point, use 8 connections/processor

Agenda .NET Design Guidelines  Memory Management  Data Access  Internet Services  Threading  Security

Threading General Tips  Avoid locks whenever possible  Don’t provide static methods that alter static state  Asynchronous invocation via delegates are the preferred threading mechanism

Threading Synchronization  Starvation is caused by multiple threads contending for a resource  The Monitor and ReaderWriterLock are designed to prevent starvation

Agenda .NET Design Guidelines  Memory Management  Data Access  Internet Services  Threading  Security

Security Key Concepts  Use the principal of least privilege  Don’t run Visual Studio with admin privileges  Use the runas utility C:\>runas /user:timmc\administrator cmd Enter password for timmc\administrator:  Lock down security policy early

Security Code Access Security  Access to a protected resource  The ability to perform a protected operation FileIOPermission permission = new FileIOPermission(PermissionState.None); permission.AllLocalFiles = FileIOPermissionAccess.Read;

Security Role-Based Security  Imperative (old way) public void DoTransaction() { IPrincipal principal = Thread.CurrentPrincipal; if (!principal.IsInRole("Managers")) { throw new SecurityException("Not a " + "manager!"); } // OK, do the transaction... }

Security Role-Based Security  Imperative (new way) public void DoTransaction() { PrincipalPermission permission = new PrincipalPermission(null, "Managers"); permission.Demand(); // Now do the transaction... }

Security Role-Based Security  Declarative [PrincipalPermission(SecurityAction.Demand, Role="Managers")] void DoTransaction() { // this time, really // do the transaction... }

Session Summary  Write consistent and predictable code  Write scalable, high-performance code  Write secure code

For More Information…  MSDN Web site at  msdn.microsoft.com  MSDN Magazine 

For More Information…  Microsoft Visual Studio.NET Documentation  sp?url=/nhp/Default.asp?contentid=

MS Press Essential Resources for Developers To find the latest developer related titles visit