-----------------------------------------------------------

New Message on MumbaiUserGroup

-----------------------------------------------------------
From: Swapnil_B1
Message 1 in Discussion

 
Session State Provider 
Session state providers provide the interface between ASP.NET session state and 
session state data sources. The two most common reasons for writing a custom 
session state provider are: 
·                       You wish to store session state in a data source that 
is not supported by the session state providers included with the .NET 
Framework, such as an Oracle database.  
·                       You wish to store session state in a SQL Server 
database whose schema differs from that of the database used by 
System.Web.SessionState.SqlSessionStateStore.  
Core ASP.NET session state services are provided by 
System.Web.SessionState.SessionStateModule, instances of which are referred to 
as session state modules. Session state modules encapsulate session state in 
instances of System.Web.SessionState.SessionStateStoreData, allocating one 
SessionStateStoreData per session (per user). The fundamental job of a session 
state provider is to serialize SessionStateDataStores to session state data 
sources and deserialize them on demand. SessionStateDataStore has three 
properties that must be serialized in order to hydrate class instances:  
·                       Items, which encapsulates a session's non-static 
objects  
·                       StaticObjects, which encapsulates a session's static 
objects  
·                       Timeout, which specifies the session's time-out (in 
minutes)  
Items and StaticObjects can be serialized and deserialized easily enough by 
calling their Serialize and Deserialize methods. The Timeout property is a 
simple System.Int32 and is therefore also easily serialized and deserialized. 
Thus, if sssd is a reference to an instance of SessionStateStoreData, the core 
logic to write the contents of a session to a session state data source is 
often no more complicated than this:  
One of the challenges to writing a session state provider is implementing a 
locking mechanism that prevents a given session from being accessed by two or 
more concurrent requests. That mechanism ensures the consistency of session 
state data by preventing one request from reading a session at the same time 
that another request is writing it. The locking mechanism must work even if the 
session state data source is a remote resource shared by several Web servers.  
Developers writing custom session state providers begin by deriving from 
System.Web.SessionState.SessionStateStoreProviderBase, which derives from 
ProviderBase and adds abstract methods defining the basic characteristics of a 
session state provider  
Synchronizing Concurrent Accesses 
ASP.NET applications are inherently multithreaded. Because requests that arrive 
in parallel are processed on concurrent threads drawn from a thread pool, it's 
possible that two or more requests targeting the same session will execute at 
the same time. (The classic example is when a page contains two frames, each 
targeting a different ASPX in the same application, causing the browser to 
submit overlapping requests for the two pages.) To avoid data collisions and 
erratic behavior, the provider "locks" the session when it begins processing 
the first request, causing other requests targeting the same session to wait 
for the lock to come free.  
Because there's no harm in allowing concurrent requests to perform overlapping 
reads, the lock is typically implemented as a reader/writer lock-that is, one 
that allows any number of threads to read a session but that prevents 
overlapping reads and writes as well as overlapping writes.  
Which brings up two very important questions: 
1.           How does a session state provider know when to apply a lock?  
2.           How does the provider know whether to treat a request as a reader 
or a writer? 
There are 3 ways to handle the above scenarios is by implementing 
IRequiresSessionState, IReadOnlySessionState Interfaces in your asp.net pages. 
If the requested page implements the IRequiresSessionState interface (by 
default, all pages implement IRequiresSessionState), ASP.NET assumes that the 
page requires read/write access to session state. In response to the 
AcquireRequestState event fired from the pipeline, SessionStateModule calls the 
session state provider's GetItemExclusive method. If the targeted session isn't 
already locked, GetItemExclusive applies a write lock and returns the requested 
data along with a lock ID (a value that uniquely identifies the lock). However, 
if the session is locked when GetItemExclusive is called, indicating that 
another request targeting the same session is currently executing, 
GetItemExclusive returns null and uses the out parameters passed to it to 
return the lock ID and the lock's age (how long, in seconds, the session has 
been locked). 
If the requested page implements the IReadOnlySessionState interface instead, 
ASP.NET assumes that the page reads but does not write session state. (The most 
common way to implement IReadOnlySessionState is to include an 
EnableSessionState="ReadOnly" attribute in the page's @ Page directive.) Rather 
than call the provider's GetItemExclusive method to retrieve the requestor's 
session state, ASP.NET calls GetItem instead. If the targeted session isn't 
locked by a writer when GetItem is called, GetItem applies a read lock and 
returns the requested data, Otherwise, GetItem returns null and uses the out 
parameters passed to it to return the lock ID and the lock's age-just like 
GetItemExclusive. 
The third possiblity—that the page implements neither IRequiresSessionState nor 
IReadOnlySessionState—tells ASP.NET that the page doesn't use session state, in 
which case SessionStateModule calls neither GetItem nor GetItemExclusive. The 
most common way to indicate that a page should implement neither interface is 
to include an EnableSessionState="false" attribute in the page's @ Page 
directive.  
Expiration Callbacks and Session_End Events 
After loading a session state provider, SessionStateModule calls the provider's 
SetItemExpireCallback method, passing in a SessionStateItemExpireCallback 
delegate that enables the provider to notify SessionStateModule when a session 
times out. If the provider supports expiration callbacks, it should save the 
delegate and return true from SetItemExpireCallback. Then, whenever a session 
times out, the provider should notify SessionStateModule that a session has 
expired by calling the callback method encapsulated in the delegate. This 
enables SessionStateModule to fire Session_End events when sessions expire.  
Cookieless Sessions 
ASP.NET supports two different types of sessions: cookied and cookieless. The 
term actually refers to the mechanism used to round-trip session IDs between 
clients and Web servers and does not imply any difference in the sessions 
themselves. Cookied sessions round-trip session IDs in HTTP cookies, while 
cookieless sessions embed session IDs in URLs using a technique known as "URL 
munging."  
In order to support cookieless sessions, a session state provider must 
implement a CreateUninitializedItem method that creates an uninitialized 
session.  
Swapnil (Swaps) 
http://swapsnet.spaces.live.com/

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to