Additional Providers

This section provides you with a brief introduction to some of the other providers that you can customize. Given what you have learned already about customizing the ProfileProvider, the MembershipProvider, and the RoleProvider, you should have no trouble using that knowledge to create your own custom providers for each of the items discussed in the rest of this section.

Introduction to the SessionState Provider

The session state provider is used to maintain session state for a web application. The session state is essentially a collection of name-value pairs that are associated with a session identifier. This session identifier is stored as a cookie (or embedded in the URL depending on session state configuration) on the client's machine. Each time a user requests a page, the session state for that user is accessible by means of the user's session identifier.

To create your own session state provider, you must override the SessionStateProviderBase class in the System.Web.SessionState namespace. The list of methods for that class is shown in Table 29.6.

Table 29.6. SessionStateStoreProviderBase Methods




Creates a new SessionStateStoreData instance for use with a web request


Creates a new session state item to the data store


Invoked at the end of a request


Obtains a session state item based on an ID and an HttpContext instance


Gets an item and locks access to that item exclusively to the caller


Initializes a web request


Releases the exclusivity lock on a session state item obtained through GetItemExclusive


Removes a state item name-value pair


Updates the expiration date of a session item


Updates the session state item and clears the exclusive lock on the item


Sets the delegate to be invoked when an item expires

Introduction to the SiteMap Provider

The SiteMap Provider is responsible for maintaining a site hierarchy. Essentially it is responsible for storing a tree structure, where each node in the tree has a description of a page as well as a link to that page. Site Map Providers make it possible to create "breadcrumb"-style controls that illustrate where a user is within a site hierarchy.

To create your own Site Map Provider, you need to create a class that inherits from System.Web.SiteMapProvider. The good thing about this particular provider is that not only does ASP.NET ship with an XML version, but the XML version is the default. Microsoft has provided an XmlSiteMapProvider that allows you to define your site map within an XML file.

However, if you are already storing your site map in a database such as SQL Server or Oracle in your own schema, you might want to create your own provider. Table 29.7 illustrates the methods of the SiteMapProvider class that you must override in order to implement your own custom Site Map Provider.

Table 29.7. SiteMapProvider Methods




Retrieves a SiteMapNode object based on a URL


Finds a site map node based on the supplied key


Gets the child site map nodes of a given site map node


Retrieves the current site map node as well as a set number of ancestors (-1 for all)


Retrieves the current site map node as well as neighborhood (under same parent) nodes


Retrieves the parent node


Optimized fetch for an ancestor node and the ancestor's descended nodes


Same as the preceding, but relative node is supplied rather than implied as "current"


Retrieves ancestor nodes of a given node


Retrieves peer (same parent) nodes of a given node


Initializes the SiteMapProvider


Indicates whether the indicated site map node can be displayed to the user in the current context

The basic idea behind the site map provider is that the code is maintaining a tree structure with page-related information. You can come up with a fairly simple schema to manage this. The caveat here is that often many tree structures in relational databases perform slowly, so when implementing your own Site Map provider make sure to take advantage of the Hintxxxx methods and provide very fast (and cacheable) results.

Microsoft Visual C# 2005 Unleashed
Microsoft Visual C# 2005 Unleashed
ISBN: 0672327767
EAN: 2147483647
Year: 2004
Pages: 298 © 2008-2017.
If you may any questions please contact us: