
Few Best Coding Practices for ASP .NETBe it any software language, the features that you opt from the language and the way you code reflects the Performance of an Application. Few such features are discussed below. Use NGEN.EXE to Fasten Application Loading NGEN.EXE
is the Navigator Image Generator Utility. This utility runs the Just-In-Time
(JIT) Compiler. The machine code generated by the compiler is cached as
Native Images in the disk. During runtime, these images in the cache are
used to run the code. This avoids generating the code dynamically and
thereby it fastens the application startup/loading time. To install NGEN.EXE,
use the following command as part of Application Setup Program:
When you
execute the above command, assemblies that have high impact on application
loading/start up are precompiled and stored in native cache of the disk. The command
to uninstall this utility is as follows: Ensure
Disabling of Debug During Deployment of the Application When you
create a new application, Debug mode is enabled by default. This is helpful
during Development phase. But during Deployment of an application in production
environment, it highly affects the performance of your application. The
reason mainly because the caching is not done when debug mode is enabled.
So the scripts, libraries and static images have to be downloaded on each
request. Hence always ensure that Debug mode is disabled before deployment.
You can easily do this by setting the attribute debug as false
inside the <compilation> section of Web.config file. Given below
is a fragment of Web.config file which has debug mode disabled: <configuration> Usage
of & Versus StringBuilder for String Concatenation Usage of
& or StringBuilder depends on the number of concatenations
that has to be done. If you are going to do less than five concatenations,
then its better you use &. Incase if its going to
be five or more concatenations, then usage of StringBuilder is recommended.
The reason because String is immutable and StringBuilder is mutable. Given
below are the sample code fragments so that you can understand things
much better: Dim strBldr
As New StringBuilder(The Fruits which I like are ) Use Caching
to Avoid Reloading of Pages In a web
application, you might need to access certain pages more frequently. Instead
of reloading those pages every time, the page content can be cached. This
improves performance and increases throughput. For this cache feature
got to be enabled, and ASP.NET has a directive termed @OUTPUTCACHE <%@ OutputCache
Duration = 25 VaryByParam = UserName %> Duration
= 25 means that the page is cached for 25 seconds. If the
request for reloading the page is placed within 25 seconds then the content
will be fetched from the cache. If the request is after 25 seconds then
the page will be regenerated dynamically. VaryByParam
can have one of the following values: VaryByParam=<Specific
Parameter name>: Assuming that the page request contains two parameters
username and securitykey, the url might look like: Here the
parameters are username and securitykey. If VaryByParam=username
then the content will be fetched from the cache until the page request
is done for the same username. To make things much clearer for you
After the
initial request made as shown above, the content will be cached. Now if
the next request comes with the parameters as shown below: http://localhost/testApp/LoginForm.aspx?username=testuser&securitykey=1234 The page
content will be displayed from the cache because the username is testuser
in both the cases If the request is from a different user (as shown below),
then the page will be regenerated dynamically. http://localhost/testApp/LoginForm.aspx?username=adminuser&securitykey=1234 Values of
more than one parameter can also be checked in one go. For example, VaryByParam=username;securitykey VaryByParam=None:
If no parameter has to be checked against VaryByParam=*:
Check against all parameters in the request. Instead of specifying VaryByParam=username;securitykey,
we can simply specify it as VaryByParam=*
_______________________________________________________________________
FREE
Subscription
Subscribe
to our mailing list and receive new articles Note
: We never rent, trade, or sell my email lists to Visit
.NET Programming Tutorial Homepage ______________________________________________________ |