Click here to Skip to main content
15,565,020 members
Articles / Web Development / ASP.NET
Posted 1 Jan 2010

Tagged as


33 bookmarked

While developing any web site, one should keep some points in mind

Rate me:
Please Sign up or sign in to vote.
4.77/5 (31 votes)
12 Jan 2011CPOL4 min read
1) Set debug=false under compilation as follows:2) Use Server.Transfer instead of Response.Redirect.3) Always check Page.IsValid when using Validator Controls4) Use Foreach loop instead of For loop for String Iteration.5) Use Client-Side Validation. (but not all the time you have...
1) Set debug=false under compilation as follows:

2) Use Server.Transfer instead of Response.Redirect.

3) Always check Page.IsValid when using Validator Controls

4) Use Foreach loop instead of For loop for String Iteration.

5) Use Client-Side Validation. (but not all the time you have to validate even on the server side)

6) Check “Page.IsPostBack”. To avoid repetition code execution.

7) GIF and PNG are similar, but PNG typically produces a lower file size. (True, but some browsers not supporting PNG format)

8) Place a file titled app_offline.htm in the root directory of your site when updating binaries. This only works on sites hosted through IIS. Place the file in the root directory of your web site. The App_Offline.htm file should be at least 1KB to prevent web browsers from serving up their own local 404 file. In addition, in order for IIS to recognize the need to serve up the App_Offline.htm file, a valid .aspx file AND a valid web.config file need to also be in the site root. For example, if you deploy by deleting your site and copying files (I know... horrid, but it happens), then the app_offline.htm will not get served up by IIS until those files exist.

9) Turn off Tracing unless until required. (by default it's off, use on the pages where it's required)
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/>

10) Precompiled pages and disable AutoEventWireup; setting the AutoEventWireup attribute to false in the Machine.config file.

11) Turn off Session State, if not required.
<sessionstate timeout="20" cookieless="false" mode="Off" stateconnectionstring="tcpip=" sqlconnectionstring="data source=;Trusted_Connection=no">

12) Select the Release mode before making the final Build for your application.

This option is available in the Top Frame just under the Window Menu option. By default, the Mode is Debug

13) Disable ViewState when not required.

14) Avoid frequent round trips to the Database.

15) Use Caching to improve the performance of your application.

16) Validate all Input received from the Users.

17) Use Finally Method to kill resources. (But not in the case of using)

18) The String and Stringbuilder Magic.

It is nice to use Stringbuilder instead of String when string are Amended. Strings occupy different memory location in every time of amended where stringbuilder use single memory location

19) Never use object value directly; first get object value in local variable and then use. It takes more time then variable reading.

20) Avoid Exceptions: Use If condition (if it is check proper condition)

21) Code optimization: Avoid using code like x = x +1; it is always better to use x+=1.

22) Data Access Techniques: DataReaders provide a fast and efficient method of data retrieval. DataReader is much faster than DataSets as far as performance is concerned

23) Before doing a bulky ASP code processing, you can check to make sure Response.IsClientConnected.

24) As always, avoid session variables because each ASP page runs in a different thread and session calls will be serialized one by one. So, this will slow down the application. Instead of session variables you can use the QueryString collection or hidden variables in the form which holds the values.

25) Enabling buffering will improve the performance, like
<% response.buffer=true %>

Then use:
<% response.flush=true %>

26) Use Repeater control instead of DataGrid , DataList, Because It is efficient, customizable, and programmable.

27) Data listing is more time consume when large data are retrieve from database.

Paging will display only particular data but take load of all data.

Fetch only data that is needed for current page.

28) Avoid Inline JavaScript and CSS

29) Use single css file instead of multiple css file.

Try your best to combine all your CSS based classes into a single .css file as lot of .css files will cause a large amount of requests, regardless of the file sizes.

.css files are normally cached by browsers, so a single and heavy .css file doesn’t cause a long wait on each page request.

Inline .css classes could make HTML heavy, so again: go ahead with a single.css file.

30) Reduce cookie size

31) Compress CSS, JavaScript and Images

Online compressors are available; to compress file please refers following web and Replace your file content with optimize code.[^] for CSS compression[^] . For JS Compression

32 .Use Cache appropriately

i. Page output caching:
<%@ OutputCache Duration="3600" VaryByParam="none" %>

ii. Page fragment caching:

Write a Page output caching code into each User Control

iii. Data caching:
<script language="C#" runat="server">

    Protected void Page_Load (Object src, EventArgs e) {

    DataView dv = (DataView) Cache. Get ("EmployeesDataView");

    If (dv == null) { // wasn't thereSqlConnection conn =

    new SqlConnection ("server=localhost;uid=sa;pwd=;database=Test");

    SqlDataAdapter da =new SqlDataAdapter ("select * from Employees", conn);

    Dataset ds = new DataSet();da.Fill(ds, "Employees");

    dv = ds.Tables["Employees"].DefaultView;

    Cache.Insert ("EmployeesDataView", dv);conn.Close();}


    Response.Write ("<h2>Loaded employees from data cache! </h2>");

    lb1.DataSource = dv;

    lb1.DataTextField = "Name";

    lb1.DataValueField = "Age";

    DataBind () ;}


33) Use server side compression software such as Port80s[^]

34) Usage of "using" and I don't know why it's not yet published.

35) Don't make the member variables public or proteted, try to keep private and use public/protected as properties.

36) Use strString=string.Empty instead of strString="" . [And perhaps instead of strString=null also (?)]

37) Make your page files as light as possible. That is try to avoid unnecessary markups, e.g. use div elements instead of tables.

38) Write static messages in div and make it visible when necessary. This is faster than letting server set Text property of your label or div.

39) Retrieve data from database at once, if possible. Don't add up to database trip as far as possible. For this, combine the datafields from different tables and select them.

40) Use short ID name for WebControl


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Comments and Discussions

General+4 - you are missing the extra one, as no reason given for e... Pin
Reiss6-Oct-11 22:47
professionalReiss6-Oct-11 22:47 
GeneralReason for my vote of 5 Good One. Pin
Anurag Gandhi2-Oct-11 21:43
professionalAnurag Gandhi2-Oct-11 21:43 
GeneralGreat list but a simple one or two sentence "why" would be a... Pin
KenHeer117-Jan-11 4:47
KenHeer117-Jan-11 4:47 
GeneralRe: agreed... why??? Pin
EngleA18-Jan-11 5:24
EngleA18-Jan-11 5:24 
Generalwhy use div instead of table ? I saw some people talk about ... Pin
Xmen Real 16-Jan-11 5:29
professional Xmen Real 16-Jan-11 5:29 
GeneralInteresting, thanks. Pin
Dr.Walt Fair, PE13-Jan-11 15:16
professionalDr.Walt Fair, PE13-Jan-11 15:16 
GeneralReason for my vote of 5 Good One! Pin
Anupama Roy12-Jan-11 19:32
Anupama Roy12-Jan-11 19:32 
GeneralReason for my vote of 5 Good Article, excellent for beginner... Pin
Dalek Dave12-Jan-11 14:46
professionalDalek Dave12-Jan-11 14:46 
GeneralI took the liberty of correcting the CODE BLOCK and INLINE C... Pin
Dalek Dave12-Jan-11 14:46
professionalDalek Dave12-Jan-11 14:46 
Generalgood tips Pin
EngleA18-Jan-11 5:27
EngleA18-Jan-11 5:27 
GeneralNice one! Pin
MrAlexMaslov13-Jan-11 18:08
MrAlexMaslov13-Jan-11 18:08 
GeneralApplication Offline and Feedback Pin
Steve Costello12-Jan-11 11:34
Steve Costello12-Jan-11 11:34 
GeneralRe: Application Offline and Feedback Pin
Dalek Dave12-Jan-11 14:47
professionalDalek Dave12-Jan-11 14:47 
GeneralPoints Pin
EuGenius_Krivbass29-Jan-10 2:11
EuGenius_Krivbass29-Jan-10 2:11 
GeneralTip/Trick Pin
Kaushal Arora1-Jan-10 19:51
Kaushal Arora1-Jan-10 19:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.