What is SQL Cache Dependency in ASP.NET 2.0?

SQL cache dependencies is a new feature in ASP.NET 2.0 which can automatically invalidate a cached data object (such as a Dataset) when the related data is modified in the database. So for instance if you have a dataset which is tied up to a database tables any changes in the database table will invalidate the cached data object which can be a dataset or a data source.

How do we enable SQL Cache Dependency in ASP.NET 2.0?

Below are the broader steps to enable a SQL Cache Dependency:-

•       Enable notifications for the database.

•       Enable notifications for individual tables.

•       Enable ASP.NET polling using “web.config” file

•       Finally use the Cache dependency object in your ASP.NET code

Enable notifications for the database.

Before you can use SQL Server cache invalidation, you need to enable notifications for the database. This task is performed with the aspnet_regsql.exe command-line utility, which is located in the c:\[WinDir]\Microsoft.NET\Framework\[Version] directory.

aspnet_regsql -ed -E -d Northwind

-ed :- command-line switch

-E: – Use trusted connection

-S: – Specify server name it other than the current computer you are working on

-d: – Database Name

So More >

Can we post and access view state in another application?

You can post back to any page and pages in another application, too. But if you are posting pages to another application, the PreviousPage property will return null. This is a significant restriction, as it means that if you want to use the view state, you are confined, for example, to posting to pages in the same virtual directory. Even so, this is a highly acceptable addition to the functionality of ASP.NET.

How do we access viewstate value of this page in the next page ?

View state is page specific; it contains information about controls embedded on the particular page. ASP.NET 2.0 resolves this by embedding a hidden input field name, __POSTBACK . This field is embedded only when there is an IButtonControl on the page and its PostBackUrl property is set to a non-null value. This field contains the view state information of the poster page. To access the view state of the poster page, you can use the new PreviousPage property of the page:

Page poster = this.PreviousPage;

Then you can find any control from the previous page and read its state:

Label posterLabel = poster.findControl(“myLabel”);

string More >

What is cross page posting?

By default, button controls in ASP.NET pages post back to the same page that contains the button, where you can write an event handler for the post. In most cases this is the desired behavior, but occasionaly you will also want to be able to post to another page in your application. The Server.Transfer method can be used to move between pages, however the URL doesn’t change. Instead, the cross page posting feature in ASP.NET 2.0 allows you to fire a normal post back to a different page in the application. In the target page, you can then access the More >

What is Absolute and Sliding expiration?

Absolute Expiration allows you to specify the duration of the cache, starting from the time the cache is activated. The following example shows that the cache has a cache dependency specified, as well as an expiration time of one minute.

Cache.Insert(“announcement”, announcement, depends, _

DateTime.Now.AddMinutes(1), Nothing)

Sliding Expiration specifies that the cache will expire if a request is not made within a specified duration. Sliding expiration policy is useful whenever you have a large number of items that need to be cached, because this policy enables you to keep only the most frequently accessed items in memory. For example, the following code specifies More >

What are benefits and limitations of using Cookies?

Following are benefits of using cookies for state management :-

?   No server resources are required as they are stored in client. ?   They are light weight and simple to use

Following are limitation of using cookies :-

?   Most browsers place a 4096-byte limit on the size of a cookie, although support for 8192-byte cookies is becoming more common in the new browser and client-device versions available today.

?   Some users disable their browser or client device’s ability to receive cookies, thereby limiting the use of cookies.

?   Cookies can be tampered and thus creating a security hole. ?   Cookies can expire thus leading More >

Where do you specify session state mode in ASP.NET?

<sessionState mode=”SQLServer”

stateConnectionString=”tcpip=192.168.1.1:42424″

sqlConnectionString=”data source=192.168.1.1; Integrated Security=SSPI”

cookieless=”false” timeout=”20″

/>

Above is sample session state mode specified for SQL SERVER

Can you compare ASP.NET sessions with classic ASP?

ASP.NET session caches per user session state. It basically uses “HttpSessionState” class.

Following are the limitations in classic ASP sessions :-

?   ASP session state is dependent on IIS process very heavily. So if IIS restarts ASP session variables are also recycled.ASP.NET session can be independent of the hosting environment thus ASP.NET session can maintained even if IIS reboots.

?   ASP session state has no inherent solution to work with Web Farms.ASP.NET session can be stored in state server and SQL SERVER which can support multiple server.

?   ASP session only functions when browser supports cookies.ASP.NET session can be used with browser side cookies More >

What are dependencies in cache and types of dependencies ?

When you add an item to the cache, you can define dependency relationships that can force that item to be removed from the cache under specific activities of dependencies.Example if the cache object is dependent on file and when the file data changes you want the cache object to be update. Following are the supported dependency :-

?   File dependency :- Allows you to invalidate a specific cache item when a disk based file or files change.

?   Time-based expiration :- Allows you to invalidate a specific cache item

depending on predefined time.

?   Key dependency :-Allows you to invalidate a specific cache item More >