Few tips for ASP.Net developer


Here are few tips on ASP.Net:

By default session state is On. To turn off session state across the application change <sessionState> mode value to Off in the web.config. You can also turn this off for a specific page by :
<%@ Page language=”c#” Codebehind=”WebForm1.aspx.cs”
AutoEventWireup=”false” Inherits=”WebApplication1.WebForm1

EnableSessionState=”false” %>

2)      OutputBuffering
Buffering is enabled by default, ASP.NET batches work on the server and avoid chatty communication with the client. You can batch all you work on the server by <%response.buffer=true%> and then run <%response.flush=true%> to output data.

You should avoid server-side validations as it will consume valuable resources on server and causes more chat back and forth.

4)      ASP.Net Controls
ASP.Net has lot of controls that were developed are heavy and not scalable from performance standpoint in html like DataList, DataGrid and DataView control.

Redirect should only be used when transferring people to another physical web server, while transferring within your server use .Transfer as it will save lot of needless HTTP requests.

The Page.IsValid property tells you whether the validation succeeded or not. It is called only after the Page.Validate method. If any bad data is received the IsValid flag is set to false, it also helps to determine whether to proceed with PostBack event or not.

Make sure to use Release Build mode instead of Debug because as the symbolic debug information is not emitted, the size of final executable is lesser than a debug executable.

8)      Turn offTracing
ASP.Net tracing enables you to view diagnostic information about a single request for a page which adds a lot of overhead to your application that is not needed in a production environment.
<trace enabled=”false” pageOutput=”false” />
<trace enabled=”false” requestLimit=”10 pageOutput=”false” traceMode=”SortByTime” localOnly=”true”/>
<compilation debug=”false” />

9)      AvoidException
You should avoid throwing and handling useless exceptions as they cause slowdowns in web applications as well as windows applications. So write your code in such a way that such exceptions are not thrown.

Caching is the process of storing frequently used data in memory since retrieving data from memory is much more efficient than retrieving the data from database. ASP.Net has several facilities to support caching: Cache API for storing data and an Output Cache to store frequently requested pages.

Post a Comment