This article provides consolidated guidelines/checklist for writing scalable, clean and high performance web applications using ASP.NET. Close adherence to the rules will help developers and code reviewers to understand a piece of code.
The article is divided into three parts as mentioned below.
- Scalable and Maintainable
- Meeting all the security standards
- Giving high performance.
The following guidelines list specific techniques that you can use to avoid writing code that does not perform at acceptable levels.
Scope : Project Design & Scalability
- Logically partition your application logic into presentation, business, and data access layers. This helps to create maintainable code, monitor and optimize the performance of each layer separately.
- Derive all the web pages form common page. This common page can contain common code such as error handling. Tracing, Session validity etc.
- Use web.config to declare flags and constant variables.
- Use resource/XML file for all the error messages. Do not hard code the error messages in the code.
- Appropriate directory structure should be followed for the web application.
Scope : ASPX Page Design
- Web page should contain appropriate title.
- Page Layout should be set to ‘Flow layout’.
- Where possible logically partition the pages. Use of div layout instead of table layout
- Use Html controls instead of server controls wherever possible.
- Style sheet should be used to apply styles.
- Maxlength property should be set for all editable controls.
- Validation controls should be placed in the order corresponding to the order of controls placed on the screen.
- Disable View State property for the controls / for the whole page where it is not required.
- Usage of View state should be avoided to store bulky data
- Code should be written to set focus to the first control of the web form.
- In web page, the portions which are static in nature like several links. Instead of writing those controls in HTML, store the whole html string in a variable in JavaScript and call document.write in html.
- Put “alt” to all the images
- The page should support all the text size of the browser(zoom in/out)
- Set proper “tabIndex” for all the HTML elements
- Device independent event handlers should be used
- Set appropriate text to the “summary” attribute of the HTML table element
- Set appropriate text to the “title” attribute of the HTML elements such as anchor tags
- If your are using a repeater control or a table having repeated columns in your web page then instead of specifying the default attributes for each column Item Template use <COL> attribute in header template
- Tune web.config to application specific needs. Some are “Authentication”, “SessionState”, and “AutoEventWireup”, “Encoding” etc.
Scope : ASPX code Behind
- “QueryString” parameters should be checked for null before use.
- “Session” values should be checked for null before they are accessed.
- Disable session state if you do not use it
- Avoid using Page.DataBind.
- Use cookies, query strings, and hidden controls for storing lightweight, user-specific state
- Use application state to share static, read-only data. Use static properties instead of the Application object to store application state
- Use Response.Write for formatting output
- Use the += operator when the number of appends is known. Use the ‘StringBuilder’ object when the number of appends is unknown
- Server.Transfer used instead of Response.Redirect. To transfer to pages in other applications, you must use Response.Redirect. When you use Response.Redirect, ensure you use the overloaded method that accepts a Boolean second parameter, and pass a value of false to ensure an internal exception is not raised.
- If we need to load content of the page from XML file, we can use JavaScript to load the content and we can use client side div instead of server side div
- If page is required to be fetched every time from web server then explicitly disable page caching. Use caching and Page output wherever possible.
- All required constant values should be defined as private constants in the beginning of the file and not hard coded in the code.
- Regions should be used to group related functions, properties and variables.
- All variables should be initialized before use.
- Code should contain exception handling.
- Prefer basic types to reduce serialization costs.
- Remove unused HTTP modules from the pipeline.
Scope : Exception Handling
- Finally block should be used for cleanup code.
- Do not catch exceptions that you cannot handle.
- Exceptions should be wrapped and re-thrown only when additional information is being added to the exception.
- Order exceptions in the catch block appropriately.
- Log as much information as possible from the exceptions.
- Write code that avoids exceptions.
- When exceptions are thrown from the application, it must not reveal the SQL information like tables, connection strings, column names, etc…
- Use try/finally on disposable resources
- Implement a Global.asax error handler
- For client side (JavaScript) exceptions we can trap the exception and show user friendly message to client in alert or message box.
- Exceptions should be logged and appropriate customized error message must be shown in the front-end.
We shall discus the next two topics in another article, Hope you enjoyed the article. Please pen down your comments
Related Posts
- ASP.Net Developers Checklist – Security Checklist
- ASP.Net Performance Improvement Tips
- ASP.Net Tutorial: Wizard Control
- Handling ASP.Net Controls in JavaScript
- Call ASP.net MVC Server side function using Jquery Ajax
Tags: asp.net, dotnet developers checklist, Quality Document, Scalablity and Maintainablity





useful list
For point “Use try/finally on disposable resources ” I think will be better “Using” keyword.
Greetz