ASP.NET supports three types of caching:
• Output Caching: Caches the output from an entire page and returns it for future requests instead of re-executing the requested page.
• Fragment Caching: Caches just a part of a page which can then be reused even while other parts of the page are being dynamically generated.
• Data Caching: Programmatically caches arbitrary objects for later reuse without re-incurring the overhead of creating them.
Which type of caching you decide to use obviously depends on your situation, but I'll briefly cover them all so you can make an informed decision.
Output Caching
Output caching is the simplest of the caching options offered by ASP.NET. It is useful when an entire page can be cached as a whole and is analogous to most of the caching solutions that were available under classic ASP. It takes a dynamically generated page and stores the HTML result right before it is sent to the client. Then it reuses this HTML for future requests bypassing the execution of the original code.
Telling ASP.NET to cache a page is extremely simple. You simply add the OutputCache directive to the page you wish to cache.
<%@ OutputCache Duration="30" VaryByParam="none" %>
The resulting caching is similar to the caching done by browsers and proxy servers, but does have one extremely important difference... you can tell a page which parameters to the page will have an effect on the output and the caching engine will cache separate versions based on the parameters you specify. This is done using the VaryByParam attribute of the OutputCache directive. The code listing below (a shortened version of output_vary.aspx from the zip file available at the end of this article) illustrates a very simple example of output caching.
<%@ Page Language="VB" %>
<%@ OutputCache Duration="30" VaryByParam="test" %>
<html>
<body bgcolor="#FFFFFF">
<p>
This page was generated at: <strong><%= Now() %></strong>
</p>
</body>
</html>
This piece of code will cache the result for 30 seconds. During that time, responses for all requests for the page will be served from the cache. It also specifies that the caching should vary by the parameter "test". As such, the page will cache a different version for each value of "test" that it is passed and will return the appropriate version based on the value of "test" in the incoming requests.
Fragment Caching
Sometimes it's not possible to cache an entire page. For example, many shopping sites like to greet their users by name. It wouldn't look very good if you went to a site and instead of using your name to greet you it used mine! In the past this often meant that caching wasn't a viable option for these pages. ASP.NET handles this by what they call fragment caching.
Honestly, I find this a little misleading... while you can technically cache part of a page, in order to do so you need to make the section to be cached into a user control and set the OutputCache directive in the new user control. Then you use this control from your dynamic page. The solution works well, but in my mind I think of it as caching a separate mini-page and not really a fragment of a page. I guess it's just semantics, but it is a separate file so it can be a little bit of work to implement.
The caching part is very similar to the code above. Aside from making the section a user control and then using the user control (which we covered in our User Controls lesson) it's pretty boring. There's a sample in the zip file, but I'm not including the code here.
Data Caching
This is the most powerful of the caching options available in ASP.NET. Using data caching you can programmatically cache anything you want for as long as you want. The caching system exposes itself in a dictionary type format meaning items are stored in name/value pairs. You cache an item under a certain name and then when you request that name you get the item back. It's similar to an array or even a simple variable.
In addition to just placing an object into the cache you can set all sorts of properties. The object can be set to expire at a fixed time and date, after a period of inactivity, or when a file or other object in the cache is changed.
The main thing to watch out for with data caching is that items you place in the cache are not guaranteed to be there when you want them back. While it does add some work (you always have to check your object exists after you retrieve it), this scavenging really is a good thing. It gives the caching engine the flexibility to dispose of things that aren't being used or dump parts of the cache if the system starts running out of memory.
Here's a simple example of data caching. Once again it's simply a streamlined version of the script in the zip file.
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim strTimestamp As String
' Retrieve our object
strTimestamp = Cache.Get("SomeData")
' Check to see if we got our object back or not.
' If not, deal with it:
If strTimestamp Is Nothing Then
' Assign a value to our object
strTimestamp = Now()
' Insert into cache:
Cache.Insert("SomeData", strTimestamp, Nothing, _
DateTime.Now.AddMinutes(.5), TimeSpan.Zero)
End If
Caching Rules... Get The Code
If you couldn't tell by now, I really like caching. It's an easy way to make your web pages and applications faster and it really doesn't cost you anything except for a little bit of time to figure out what to cache and for how long to cache it. It does use some memory, but with the price of memory these days, adding a little more (if needed) is a small price to pay for a faster web site.
As usual, the code from this lesson is all zipped up in a nice little file so you can download it and play with it on your own.
Thursday, March 4, 2010
Life-cycle Events
PreInit
Use this event for the following:
Check the IsPostBack property to determine whether this is the first time the page is being processed.
Create or re-create dynamic controls.
Set a master page dynamically.
Set the Theme property dynamically.
Read or set profile property values.
NoteNote:
If the request is a postback, the values of the controls have not yet been restored from view state. If you set a control property at this stage, its value might be overwritten in the next event.
Init
Raised after all controls have been initialized and any skin settings have been applied. Use this event to read or initialize control properties.
InitComplete
Raised by the Page object. Use this event for processing tasks that require all initialization be complete.
PreLoad
Use this event if you need to perform processing on your page or control before the Load event.
Before the Page instance raises this event, it loads view state for itself and all controls, and then processes any postback data included with the Request instance.
Load
The Page calls the OnLoad event method on the Page, then recursively does the same for each child control, which does the same for each of its child controls until the page and all controls are loaded.
Use the OnLoad event method to set properties in controls and establish database connections.
Control events
Use these events to handle specific control events, such as a Button control's Click event or a TextBox control's TextChanged event.
NoteNote:
In a postback request, if the page contains validator controls, check the IsValid property of the Page and of individual validation controls before performing any processing.
LoadComplete
Use this event for tasks that require that all other controls on the page be loaded.
PreRender
Before this event occurs:
The Page object calls EnsureChildControls for each control and for the page.
Each data bound control whose DataSourceID property is set calls its DataBind method. For more information, see Data Binding Events for Data-Bound Controls later in this topic.
The PreRender event occurs for each control on the page. Use the event to make final changes to the contents of the page or its controls.
SaveStateComplete
Before this event occurs, ViewState has been saved for the page and for all controls. Any changes to the page or controls at this point will be ignored.
Use this event perform tasks that require view state to be saved, but that do not make any changes to controls.
Render
This is not an event; instead, at this stage of processing, the Page object calls this method on each control. All ASP.NET Web server controls have a Render method that writes out the control's markup that is sent to the browser.
If you create a custom control, you typically override this method to output the control's markup. However, if your custom control incorporates only standard ASP.NET Web server controls and no custom markup, you do not need to override the Render method. For more information, see Developing Custom ASP.NET Server Controls.
A user control (an .ascx file) automatically incorporates rendering, so you do not need to explicitly render the control in code.
Unload
This event occurs for each control and then for the page. In controls, use this event to do final cleanup for specific controls, such as closing control-specific database connections.
For the page itself, use this event to do final cleanup work, such as closing open files and database connections, or finishing up logging or other request-specific tasks.
NoteNote:
During the unload stage, the page and its controls have been rendered, so you cannot make further changes to the response stream. If you attempt to call a method such as the Response.Write method, the page will throw an exception.
Use this event for the following:
Check the IsPostBack property to determine whether this is the first time the page is being processed.
Create or re-create dynamic controls.
Set a master page dynamically.
Set the Theme property dynamically.
Read or set profile property values.
NoteNote:
If the request is a postback, the values of the controls have not yet been restored from view state. If you set a control property at this stage, its value might be overwritten in the next event.
Init
Raised after all controls have been initialized and any skin settings have been applied. Use this event to read or initialize control properties.
InitComplete
Raised by the Page object. Use this event for processing tasks that require all initialization be complete.
PreLoad
Use this event if you need to perform processing on your page or control before the Load event.
Before the Page instance raises this event, it loads view state for itself and all controls, and then processes any postback data included with the Request instance.
Load
The Page calls the OnLoad event method on the Page, then recursively does the same for each child control, which does the same for each of its child controls until the page and all controls are loaded.
Use the OnLoad event method to set properties in controls and establish database connections.
Control events
Use these events to handle specific control events, such as a Button control's Click event or a TextBox control's TextChanged event.
NoteNote:
In a postback request, if the page contains validator controls, check the IsValid property of the Page and of individual validation controls before performing any processing.
LoadComplete
Use this event for tasks that require that all other controls on the page be loaded.
PreRender
Before this event occurs:
The Page object calls EnsureChildControls for each control and for the page.
Each data bound control whose DataSourceID property is set calls its DataBind method. For more information, see Data Binding Events for Data-Bound Controls later in this topic.
The PreRender event occurs for each control on the page. Use the event to make final changes to the contents of the page or its controls.
SaveStateComplete
Before this event occurs, ViewState has been saved for the page and for all controls. Any changes to the page or controls at this point will be ignored.
Use this event perform tasks that require view state to be saved, but that do not make any changes to controls.
Render
This is not an event; instead, at this stage of processing, the Page object calls this method on each control. All ASP.NET Web server controls have a Render method that writes out the control's markup that is sent to the browser.
If you create a custom control, you typically override this method to output the control's markup. However, if your custom control incorporates only standard ASP.NET Web server controls and no custom markup, you do not need to override the Render method. For more information, see Developing Custom ASP.NET Server Controls.
A user control (an .ascx file) automatically incorporates rendering, so you do not need to explicitly render the control in code.
Unload
This event occurs for each control and then for the page. In controls, use this event to do final cleanup for specific controls, such as closing control-specific database connections.
For the page itself, use this event to do final cleanup work, such as closing open files and database connections, or finishing up logging or other request-specific tasks.
NoteNote:
During the unload stage, the page and its controls have been rendered, so you cannot make further changes to the response stream. If you attempt to call a method such as the Response.Write method, the page will throw an exception.
Labels:
Asp.Net
General Page Life-cycle Stages :
Page request :
The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.
Start :
In the start step, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. Additionally, during the start step, the page's UICulture property is set.
Page initialization :
During page initialization, controls on the page are available and each control's UniqueID property is set. Any themes are also applied to the page. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.
Load :
During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.
Validation :
During validation, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page.
Postback event handling :
If the request is a postback, any event handlers are called.
Rendering :
Before rendering, view state is saved for the page and all controls. During the rendering phase, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream of the page's Response property.
Unload :
Unload is called after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and any cleanup is performed.
The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.
Start :
In the start step, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. Additionally, during the start step, the page's UICulture property is set.
Page initialization :
During page initialization, controls on the page are available and each control's UniqueID property is set. Any themes are also applied to the page. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.
Load :
During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.
Validation :
During validation, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page.
Postback event handling :
If the request is a postback, any event handlers are called.
Rendering :
Before rendering, view state is saved for the page and all controls. During the rendering phase, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream of the page's Response property.
Unload :
Unload is called after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and any cleanup is performed.
Labels:
Asp.Net
Wednesday, March 3, 2010
Top 10 Lorgest Bridges in World
10. Seven Mile Bridge
The Seven Mile Bridge, in the Florida Keys, runs over a channel between the Gulf of Mexico and the Florida Strait, connecting Key Vaca (the location of the city of Marathon, Florida) in the Middle Keys to Little Duck Key in the Lower Keys. Among the longest bridges in existence when it was built, it is one of the many bridges on US 1 in the Keys, where the road is called the Overseas Highway.

9. San Mateo-Hayward Bridge
The San Mateo-Hayward Bridge (commonly called San Mateo Bridge) is a bridge crossing California’s San Francisco Bay in the United States, linking the San Francisco Peninsula with the East Bay. More specifically, the bridge’s western end is in Foster City, the most recent urban addition to the eastern edge of San Mateo. The eastern end of the bridge is in Hayward. The bridge is owned by the state of California, and is maintained by Caltrans, the state highway agency.

8. Confederation Bridge
The Confederation Bridge (French: Pont de la Confédération) is a bridge spanning the Abegweit Passage of Northumberland Strait, linking Prince Edward Island with mainland New Brunswick, Canada. It was commonly referred to as the “Fixed Link” by residents of Prince Edward Island prior to its official naming. Construction took place from the fall of 1993 to the spring of 1997, costing $1.3 billion. The 12.9-kilometre (8 mi) long bridge opened on 31 May 1997.

7. Rio-Niteroi Bridge
The Rio-Niteroi Bridge is a reinforced concrete structure that connects the cities of Rio de Janeiro and Niteroi in Brazil.
Construction began symbolically on August 23, 1968, in the presence of Queen Elizabeth II of the United Kingdom and Prince Philip, Duke of Edinburgh, in their first and thus far only visit to Brazil. Actual work begun in January, 1969, and it opened on March 4, 1974.
Its official name is “President Costa e Silva Bridge”, in honor of the Brazilian president who ordered its construction. “Rio-Niteroi” started as a descriptive nickname that soon became better known than the official name. Today, hardly anyone refers to it by its official name.

6. Penang Bridge
The Penang Bridge (Jambatan Pulau Pinang in Malay) E 36 is a dual-carriageway toll bridge that connects Gelugor on the island of Penang and Seberang Prai on the mainland of Malaysia on the Malay Peninsula. The bridge is also linked to the North-South Expressway in Prai and Jelutong Expressway in Penang. It was officially opened to traffic on September 14, 1985. The total length of the bridge is 13.5 km (8.4 miles), making it among the longest bridges in the world, the longest bridge in the country as well as a national landmark. PLUS Expressway Berhad is the concession holder which manages it.

5. Vasco da Gama Bridge
The Vasco da Gama Bridge (Portuguese: Ponte Vasco da Gama, pron. IPA: [’põt(?) ‘va?ku d? ‘g?m?]) is a cable-stayed bridge flanked by viaducts and roads that spans the Tagus River near Lisbon, capital of Portugal. It is the longest bridge in Europe (including viaducts), with a total length of 17.2 km (10.7 mi), including 0.829 km (0.5 mi) for the main bridge, 11.5 km (7.1 mi) in viaducts, and 4.8 km (3.0 mi) in dedicated access roads. Its purpose is to alleviate the congestion on Lisbon’s other bridge (25 de Abril Bridge), and to join previously unconnected motorways radiating from Lisbon.

4. Chesapeake Bay Bridge
The Chesapeake Bay Bridge (commonly known as the Bay Bridge) is a major dual-span bridge in the U.S. state of Maryland; spanning the Chesapeake Bay, it connects the state’s Eastern and Western Shore regions. At 4.3 miles (7 km) in length, the original span was the world’s longest continuous over-water steel structure when it opened in 1952. The bridge is officially named the William Preston Lane, Jr. Memorial Bridge after William Preston Lane, Jr. who, as governor of Maryland, implemented its construction.

3. King Fahd Causeway
The King Fahd Causeway is multiple dike - bridge combination connecting Khobar, Saudi Arabia, and the island nation of Bahrain.
A construction agreement signed on July 8, 1981 led to construction beginning the next year. The cornerstone was laid on November 11, 1982 by King Fahd of Saudi Arabia and Sheikh Isa bin Salman al-Khalifa of Bahrain; construction continued until 1986, when the combination of several bridges and dams were completed. The causeway officially opened for use on November 25, 1986.

2. Donghai Bridge
Donghai Bridge (literally “East Sea Grand Bridge”) is the longest cross-sea bridge in the world and the longest bridge in Asia. It was completed on December 10, 2005. It has a total length of 32.5 kilometres (20.2 miles) and connects Shanghai and the offshore Yangshan deep-water port in China. Most of the bridge is a low-level viaduct. There are also cable-stayed sections to allow for the passage of large ships, largest with span of 420 m.

1. Lake Pontchartrain Causeway
The Lake Pontchartrain Causeway, or the Causeway, consists of two parallel bridges that are the longest bridges in the world by total length.[2] These parallel bridges cross Lake Pontchartrain in southern Louisiana. The longer of the two bridges is 23.87 miles (38.42 km) long. The bridges are supported by over 9,000 concrete pilings. The two bridges feature bascule spans over the navigation channel 8 miles (13 km) south of the north shore. The southern terminus of the Causeway is in Metairie, Louisiana, a suburb of New Orleans. The northern terminus is at Mandeville, Louisiana.
The Seven Mile Bridge, in the Florida Keys, runs over a channel between the Gulf of Mexico and the Florida Strait, connecting Key Vaca (the location of the city of Marathon, Florida) in the Middle Keys to Little Duck Key in the Lower Keys. Among the longest bridges in existence when it was built, it is one of the many bridges on US 1 in the Keys, where the road is called the Overseas Highway.
9. San Mateo-Hayward Bridge
The San Mateo-Hayward Bridge (commonly called San Mateo Bridge) is a bridge crossing California’s San Francisco Bay in the United States, linking the San Francisco Peninsula with the East Bay. More specifically, the bridge’s western end is in Foster City, the most recent urban addition to the eastern edge of San Mateo. The eastern end of the bridge is in Hayward. The bridge is owned by the state of California, and is maintained by Caltrans, the state highway agency.
8. Confederation Bridge
The Confederation Bridge (French: Pont de la Confédération) is a bridge spanning the Abegweit Passage of Northumberland Strait, linking Prince Edward Island with mainland New Brunswick, Canada. It was commonly referred to as the “Fixed Link” by residents of Prince Edward Island prior to its official naming. Construction took place from the fall of 1993 to the spring of 1997, costing $1.3 billion. The 12.9-kilometre (8 mi) long bridge opened on 31 May 1997.
7. Rio-Niteroi Bridge
The Rio-Niteroi Bridge is a reinforced concrete structure that connects the cities of Rio de Janeiro and Niteroi in Brazil.
Construction began symbolically on August 23, 1968, in the presence of Queen Elizabeth II of the United Kingdom and Prince Philip, Duke of Edinburgh, in their first and thus far only visit to Brazil. Actual work begun in January, 1969, and it opened on March 4, 1974.
Its official name is “President Costa e Silva Bridge”, in honor of the Brazilian president who ordered its construction. “Rio-Niteroi” started as a descriptive nickname that soon became better known than the official name. Today, hardly anyone refers to it by its official name.
6. Penang Bridge
The Penang Bridge (Jambatan Pulau Pinang in Malay) E 36 is a dual-carriageway toll bridge that connects Gelugor on the island of Penang and Seberang Prai on the mainland of Malaysia on the Malay Peninsula. The bridge is also linked to the North-South Expressway in Prai and Jelutong Expressway in Penang. It was officially opened to traffic on September 14, 1985. The total length of the bridge is 13.5 km (8.4 miles), making it among the longest bridges in the world, the longest bridge in the country as well as a national landmark. PLUS Expressway Berhad is the concession holder which manages it.
5. Vasco da Gama Bridge
The Vasco da Gama Bridge (Portuguese: Ponte Vasco da Gama, pron. IPA: [’põt(?) ‘va?ku d? ‘g?m?]) is a cable-stayed bridge flanked by viaducts and roads that spans the Tagus River near Lisbon, capital of Portugal. It is the longest bridge in Europe (including viaducts), with a total length of 17.2 km (10.7 mi), including 0.829 km (0.5 mi) for the main bridge, 11.5 km (7.1 mi) in viaducts, and 4.8 km (3.0 mi) in dedicated access roads. Its purpose is to alleviate the congestion on Lisbon’s other bridge (25 de Abril Bridge), and to join previously unconnected motorways radiating from Lisbon.
4. Chesapeake Bay Bridge
The Chesapeake Bay Bridge (commonly known as the Bay Bridge) is a major dual-span bridge in the U.S. state of Maryland; spanning the Chesapeake Bay, it connects the state’s Eastern and Western Shore regions. At 4.3 miles (7 km) in length, the original span was the world’s longest continuous over-water steel structure when it opened in 1952. The bridge is officially named the William Preston Lane, Jr. Memorial Bridge after William Preston Lane, Jr. who, as governor of Maryland, implemented its construction.
3. King Fahd Causeway
The King Fahd Causeway is multiple dike - bridge combination connecting Khobar, Saudi Arabia, and the island nation of Bahrain.
A construction agreement signed on July 8, 1981 led to construction beginning the next year. The cornerstone was laid on November 11, 1982 by King Fahd of Saudi Arabia and Sheikh Isa bin Salman al-Khalifa of Bahrain; construction continued until 1986, when the combination of several bridges and dams were completed. The causeway officially opened for use on November 25, 1986.
2. Donghai Bridge
Donghai Bridge (literally “East Sea Grand Bridge”) is the longest cross-sea bridge in the world and the longest bridge in Asia. It was completed on December 10, 2005. It has a total length of 32.5 kilometres (20.2 miles) and connects Shanghai and the offshore Yangshan deep-water port in China. Most of the bridge is a low-level viaduct. There are also cable-stayed sections to allow for the passage of large ships, largest with span of 420 m.
1. Lake Pontchartrain Causeway
The Lake Pontchartrain Causeway, or the Causeway, consists of two parallel bridges that are the longest bridges in the world by total length.[2] These parallel bridges cross Lake Pontchartrain in southern Louisiana. The longer of the two bridges is 23.87 miles (38.42 km) long. The bridges are supported by over 9,000 concrete pilings. The two bridges feature bascule spans over the navigation channel 8 miles (13 km) south of the north shore. The southern terminus of the Causeway is in Metairie, Louisiana, a suburb of New Orleans. The northern terminus is at Mandeville, Louisiana.
Labels:
General
Tuesday, February 23, 2010
Monday, February 1, 2010
Static Class and Member
Static class is a class which can be declared as Static.It contains only static member and private constructor.Private constructor prevents the class from being instantiated.So it doesn't allow to create instance of a static class using new keyword.
We can directly access methods from static class using class name.
The main features of a static class are:
* They only contain static members.
* They cannot be instantiated.
* They are sealed.
* They cannot contain Instance Constructors which means that it contains private constructor or static constructor.
Advantage :
We can directly access methods from static class using class name.
The main features of a static class are:
* They only contain static members.
* They cannot be instantiated.
* They are sealed.
* They cannot contain Instance Constructors which means that it contains private constructor or static constructor.
Advantage :
- Normally the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created.
- Static classes are sealed and therefore cannot be inherited. Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state.
Labels:
Asp.Net
Microsoft Message Queuing
Microsoft Message Queuing (MSMQ) technology enables applications running at different times to communicate across heterogeneous networks and systems that may be temporarily offline. MSMQ provides guaranteed message delivery, efficient routing, security, and priority-based messaging. It can be used to implement solutions for both asynchronous and synchronous messaging scenarios.
Labels:
Asp.Net