Whether you're using ASP.NET to develop a Web application for users or customers, chances are you want an easier way to build those apps. At the latest installment of the VSLive conference, held in Boston at the end of June 2005, Chris Kinsman, chairman of the event's ASP sessions, offered attendees tricks for building Web applications. Here are four of those tips.
Create an n-tier architecture
Anything related to business logic should be removed from ASP.NET and placed into a data layer, said Kinsman, a consultant and architect with Vergent Software and a Microsoft Regional Director. Developers should build these layers on the Enterprise Library Data Access Block, which creates standard, low-level ADO.NET code.
Using a data layer offers several benefits, Kinsman said. It can be used many times, it gives developers the flexibility to change data access methods and it is easier to write a unit test for than a UI layer. In addition, the layer puts all SQL data in one location.
Create a class for application settings
Most developers use ConfigurationSettings.AppSettings to get values from the default < app Settings > section. Kinsman doesn't like this option, since it locks a developer into only one method of reading for Web.Config, reads only one item at a time and is loosely typed.
Instead, Kinsman said, developers should create a class that supplies application settings, use shared or static methods to expose data and store settings in Web.Config, XML, Registry or Database Table. Data abstraction should be done with Enterprise Library Configuration Manager, he said: "You provide a class, and [the manager] worries about where it's going to serialize it and where it's going to store it."
Another advantage to the configuration manager is that it does the caching for you and will always call up the newest values, Kinsman said. To do this, developers must choose the option "change detection mechanism."
Use Cascading Style Sheets
Many Web applications have headers, footers or modules that are the same on dozens of sites. To keep this UI consistent, Kinsman said, developers should use style sheets instead of tables. In doing so, style sheets change but the HTML does not.
Style sheets are based on the < Div > function and implement changes across an application, not just on a single site. User controls are best for application-specific UI, Kinsman added, while server controls are ideal for multi-application solutions.
Kinsman mentioned the css Zen Garden as a good example of the use of style sheets. This site caters to graphic designers with strong CSS skills, but it offers developers sample designs and lets them submit files they have created with the style sheets.
Track users, track errors
The best way to track user or customer traffic in ASP.NET is to create a Web User log instead of a Web log, Kinsman said. A user log will provide specific details about what users were doing where and when; a regular Web log, he said, cannot easily provide this contextual information.
Exceptions and errors can also be tracked, in this case through the Control setting. Developers can set this up to send e-mail notification of any error, complete with an event log. Using the Control setting allows multiple exception targets to be tracked with one configuration, Kinsman said.
Do you have comments on this tip? Let us know.