Wednesday, December 23, 2009

Optimizing Your Asp.Net Pages For Faster Loading And Better Performance

If you read the internet and all the websites dedicated to Asp.Net you will inevitably about the wonders of the DataGrid, DataList, and Repeater to read. Although each of them has its place if you are only displaying data there is a much faster and more efficient ways to do this.

Suppose you have a page with items based on a query string. Take my article pages for instance. Each item is stored in a database and displayed on the page using the unique ID of the basethe article as stored in the database.

A normal asp page execution procedure goes something like this. The code queries the database on the article ID and then brings back that information to the page where you show it in the fashion that you want. This is a fairly straight forward approach with asp and is done all the time.

Just as we speed up our asp.net pages?

Number 1: Use Asp.Net Caching!

This is a breeze, and I do not want to goBrilliance and details of asp.net caching here because at the time of writing has this article 2780000 Google for more. Basically, instead of loading the query the database each time the page, one has only one query of the database and load that into the system cache. Subsequent calls to load the page retrieve the data from the cache to the database that have an immediate and significant performance enhancement compared. You can then use the cache, how long the cache should the businessInformation and many other features. If you use the cache, you should, if possible!

Point 2: If possible, you should not use the standard Asp.Net controls.

That's right. The standard asp.net controls are designed for rapid development and not page performance. They allow you to visit design, the grave and display of data very quickly, but their actual performance suffers because the additional cost for making it easier and speed development time and notPage execution speed.

Instead, create either a User Control or even better, a Web Custom Control is by far the fastest performance wise and very easy to create and use.

Number 3: Use an SqlDataReader or even better to use a sentence to execute command for SQL Server data retrieval and easy that a command for the database.

An asp.net SqlDataReader is a fast-forward DataReader only that the connection after it is closed the lastSeries of results. Now for my article pages we are back to only 1 particular result. In this case, we would opt for the basic set-command. If you return more than 1 outcome, would use in the table of contents for example, use the SqlDataReader because you once more sets of results.

Set up commands are stored procedures that return the data as parameters to be a result set, then looped again in order to get your data against it. So instead ofWrite your stored procedure like this, which brings back 1 result set:

Select Title, Body, Author
Of the articles
Where ArtID = 215

We can write it with a set of command like this.

Create Procedure mysp_GetArticle

@ Title varchar (200) output,
@ Body varchar (8000) output,
@ Author VARCHAR (500) Output

As

Select @ Title = Title, @ Body = Body, @ Author = Author
Of the articles
Where ArtID = 215

GO

The above query will returnonly the three parameters, and not a result or a record with a so-called, you do not have to walk through the returned data set that only 1 result in it. This second little process of work decreases the performance, so you should avoid, if possible. Combine this technique with the asp.net cache.

Number 4: Using Classes and ArrayLists to return a SqlDataReader forward.

Create a class and then, if there is more to save as a series of results to theseResults in individual instances of this class. Finally, each class stored in an ArrayList. You can only save that ArrayList into the asp.net cache. So instead of the results back from a SqlDataReader when loading your page you get them from the ArrayList which is stored in the cache. Nice huh?

Finally ... You want all of these techniques in the final results, which are being implemented in the following manner and order, would take over.

On the firstTime the page loads, query the database and delivers it to save all your data into separate classes. Then store each class in an ArrayList. If you have only one result you can only save the class in the cache. Then take your ArrayList and store it in the cache.

First you create a Web Custom Control and pass the cached ArrayList of custom controls and loop your data using the HtmlTextWriter which is very fast. Remember, every subsequent call to load thePage from the cache are called, which saves your ArraList of classes or your single class.

Certainly, a significant amount of additional coding takes to do it that way, especially if you have a proper error handling into consideration, but when you approach after that your pages be screeching fast, you will immediately notice the difference and your asp. net sites are in the correct order are carried out - data processing in the Page_Load function and the HTML display in thePage_Render function.

Also, you will not regret it and your visitors.

Happy programming!



Recommend : cola-drink pclaptops vaiolaptopbattery 24 tv series get domain name

No comments:

Post a Comment