Storing data is expensive, if a database is
involved. Be careful to match lifetime of data with the appropriate data
storage method:
|
lifetime of data
|
data storage method
|
Storage
|
|
Permanent (configuration data, etc.)
|
Application Data
|
Web server
|
|
Processing of one HTML request
|
Global.asax
|
Web server
|
|
Postback (same HTML page request processed again)
|
ViewState
|
Web page
|
|
Passed between 2 different pages
|
Query in HTML link
|
Web page
|
|
General User related data (preferred language, etc.)
|
Session Data
|
Database
|
|
User created orders, etc.
|
Transactional Data
|
Database
|
Application data like country lists, etc.,?can be
stored in the database, but should be read only once when the web server
starts. Even better is to store this data in source code, possibly with the
help of a code generator. Other application data might change from time to
time, like exchange rates. In this case reading of this data needs to be
protected by a lock.
Several pieces of ASP.NET (Global.asax, Web Form,
Web User Control) might need to share some data (for example: Header control
and Footer control need to know which language to use, but is detected in
Global.asax). Use for that purpose public members of Global.asax. The lifetime
of this data is only the creation of one HTML response. Don抰 use Context.Items,
which is slower (string search in a collection vs. no search at all).
???
???
Store session related data (Language, etc.) in the
database. This has the following advantages:
1) several
web servers can work in parallel
2) access
to session data with database tools (important for CRM statistics)
The speed disadvantage of accessing the database
server can be minimized by bundling the query for session data with another
database query which would take place anyway.
Since session data (language, etc.) is needed on
every page, Application_PreRequestHandlerExecute
in Global.asax.cs accesses
the session data and stores it in public members. They are called
CookieLanguage, CookieName, etc., since the session data is stored in the
database according to cookie data. From other page, the session data is
accessed as follows:
protected Global GlobalData;
private void Default_Init(object sender,
System.EventArgs e)
{
牋牋?GlobalData =
(Global)Context.ApplicationInstance;
牋牋?if
(GlobalData.CookieMissing) {
牋牋??/code>
???
Don抰 put server code in .ASPX files, put it in code
behind files. Code which is not user interface related or code which is used by
more than one web page should be written in a separate class file.
Example ???
The structure of the .ASPX files follows the
requirements of HTML and ASP.NET:
<%@ Page
language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false"
Inherits="PeterBox.WebSite._Default" %>
<%@ Register
TagPrefix="PBNameSpace" TagName="Header"
Src="Header.ascx" %>
<!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
牋?<head>
牋牋牋?<meta
http-equiv="content-type" content="text/html;
charset=UTF-8">
牋牋牋?and
other meta tags
牋牋牋?<title>PeterBox
- Homepage</title>
牋牋牋?<link
href="PeterBox.css" type="text/css"
rel="stylesheet">
牋?</head>
牋?<body
MS_POSITIONING="FlowLayout">
牋牋牋?<form
id="Test" method="post" runat="server">
牋牋牋牋牋?<PBNameSpace:Header
id="HPHeader" title="HomePageTitle"
runat="server">
牋牋牋牋牋?</PBNameSpace:Header>
牋牋牋牋牋?<div
style="margin-right: 10px; margin-left: 10px">
牋牋牋牋牋牋牋?Here
comes actual page content, between page header and footer
牋牋牋牋牋?
</div>
牋牋牋牋牋?
<br>
牋牋牋牋牋?<PBNameSpace:Footer
id="HPFooter" runat="server">
牋牋牋牋牋?</PBNameSpace:Footer>
牋牋牋?</form>
牋?</body>
</html>
<meta
http-equiv="content-type" content="text/html;
charset=UTF-8">
<meta
name="title" content="DotNet homepage Peter Huber">
<meta
name="author" content="contact@peterbox.com">
<meta
name="description" content="The PeterBox shows how the .NET
technology can be used to build a website, including the use of CSS, C#,
ADO.NET and SQL server. It is also the homepage of J黵gpeter Huber, Singapore.">
<meta
name="keywords" content="asp.net css .net dotnet csharp peter
huber j黵gpeter ">
<meta
name="copyright" content="?2003 Peter Huber, Singapore">
<meta
name="robots" content="all">
The HTML element <title> should start with
揚eterBox ??
<title>PeterBox
?Home Page</title>
•
General structure:
- File Header
- Using statements
- Namespace
- Class Declaration
- Control Declarations
- Member Declarations
- OnInit procedure
- InitializeComponent() (system created)
- Other event procedures as needed, in chronological order
•
Rename Page_Load
to FormName_Load.
•
Visual Studio creates events in a random order. Reorganize events
in a chronological order: Move them after InitializeComponent().
•
Visual Studio tends to lose events settings. Do it manually in InitializeComponent().
???Validation occurs only before render event
Test behavior of every page if user keys in Page URL
directly into Internet Explorer (instead using provided links and menus).
???
Any element a user can click should change if the
cursor moves over it. This can be achieved with the pseudo-class hover for
<a> elements.
a.GrayButton
{background-color: #eeeeee;}
a.GrayButton:hover
{background-color: #d0d0d0;}
It抯 a bit more difficult to achieve this effect for
buttons, Javascript has to be used.
Each link / button should have a hint (Title
attribute, ToolTip), explaining what will happen if the user clicks here.
Make sure that also the label of a radio button is
clickable.
<LABEL
for="LangGermanRadio">Deutsch</LABEL>
<INPUT
id="LangGermanRadio" type="radio" value="German"
name="radLanguage">
Images should have a hint, giving additional
information for the picture displayed.
???
???
Infragistics ???
???
Function ?Control Type
Example: ???
For speed reason, use whenever possible pure HTML
code. A server control has quite some overhead because of all the functionality
provided (event, ViewState, ?. Even if few attributes of an HTML element have
to be changed during run time, instead using HTML or Web Control, use <%=xxx %>:
<th>
牋牋?<%=AnyObject.GetAString("SomeParameter")
%>
</th>
In an HTML option, the above code wouldn抰 work due to the ?
?in GetAString(). In that case, copy everything into a protected class
variable during the Page_Load
File XXX.ASCX.CS:
Protected string
AnyObjectString = AnyObject.GetAString("SomeParameter");
File XXX.ASCX:
<A
class=HeaderLink title="<%= AnyObjectString %>"
Web Controls are preferred over HTML Control,
???
Use PBoxNameSpace as TagPrefix:
<%@ Register
TagPrefix="PBoxNameSpace" TagName="Header"
Src="Header.ascx" %>
???
Use PBoxNameSpace as TagPrefix:
<%@ Register
TagPrefix="PBoxNameSpace" Namespace="PeterBox.WebSite"
Assembly="PeterBox" %>
Datasets use DataReaders to
access the database. They provide additional functionality like keeping state
information (i.e. edited data) for certain time, which makes them about 3 times
slower than DataReaders. This information is already stored in forms on HTML
pages and DataSets are usually not needed for WebPages.
A database access is quite
time consuming for the web server, because processes on two different machines
need to be synchronized together with the LAN activities for exchanging the
data. On the other hand, there it doesn抰 take much longer to perform 2 queries
on the database instead of 1. Therefore, the number of roundtrips to the database
should be minimized. Ideally, all information exchanged with the database
(logging information, user information, page specific information) should be
processed by one stored procedure. However, if user input is involved (post
back), a second database access can often not be avoided.
???
See chapter handling ASP.NET in ms-help://MS.VSCC/MS.MSDNQTR.2002JUL.1033/dnbda/html/exceptdotnet.htm
Storing of error tracing information in a local file
if database connection is not available
???
???
Define a special console project which will run all
the tests defined in the middle tier.
•
Test with different browser and browser versions
•
Test with cookie disabled
•
Test with different regional settings and languages, is
everything properly translated ?
•
Test for down-level browser (no client validation)
•
Test shortcut keys in all languages
•
Test tab key, enter key
•
Test how it looks with different sized texts
•
Test how it looks when windows size is changed
•
Check HTML created on client (Also during peer review)
•
Placement of CSS information
- Is
inline style used where an internal style sheet should be used (a style
formatting is used more than once in one HTML page) ?
- Is
an internal style sheet used where an external style sheet should be used (a
style formatting is used on several HTML pages) ?
???
???
???
See also .Net Framework, Building Applications,
Creating ASP.NET Applications, ASP.NET Trace
Application settings ???
View traces with http://localhost/PeterBox/Trace.axd?id=0
???
Chapters Overview