Membership Service in ASP.Net 2.0

Membership Service in ASP.Net 2.0
Published on http://asp.net on 10/16/2008

Thursday, August 18, 2005

Site Navigation in ASP.Net 2.0 - Part I

Site Navigation

All of the web applications developed usually have more than one page and they are usually interconnected via some mechanism. In ASP.Net 1.x, navigation was made possible by using hyperlinks with the help of include file or user controls. They are pretty handy but not so much when the pages are moved around or their names change.

So in order to overcome this drawback, ASP.Net 2.0 introduces the new Site Navigation System. Site navigation uses the layered architecture. Controls such as Menu and TreeView provide the navigation UIs. Classes such as SiteMap and SiteMapNode provide the API that the controls rely on and also constitute an API you can use yourself if you wish. Site navigation is provider-based, and the one site map provider that comes with ASP.NET 2.0 -->XmlSiteMapProvider --> reads site maps from XML data files. By default, those files are named Web.sitemap.

Lets us discuss each on of them one at a time.

Site Maps

Site Maps help us define the layout of all the pages in the application and their inherent relation with each other. For this, one could either use the SiteMap Class or the SiteMapDataSource control.
SiteMapDataSource controls use site map providers to read site maps. They then provide the site map data to the controls they're bound to. Binding a TreeView to a SiteMapDataSource transforms each node in the site map into a TreeView node; binding a Menu to a SiteMapDataSource transforms each node in the site map into a menu item. The only site map provider that comes with ASP.NET 2.0 is XmlSiteMapProvider. It enables site maps to be read from XML files that conform to a predefined schema

Take up the following steps to create a site map-->

  • Start Visual Studio 2005 IDE.
  • Create a new ASP.Net website using C# as language on file system.
  • Right Click on solution and add a new item. From the Add item Wizard, add a new site map. Let the name be Web.sitemap (default name)
  • Add the following code to it:-

Only one sitemap element can be there in the site map file and there can be multiple siteMapNode element within the root node i.e. sitemap

Within the siteMapNode element, we have following attributes -->

  • Title --> This is actual description which appears as a hyperlink.
  • Description --> Tool Tip which comes up when we hover over that particular siteMapNode.
  • url --> this is the file located within the solution. It can be located within the root folder or within a sub-folder created within the solution.
  • Role --> the roles to which the links should be accessible.

    "Security trimming" refers to SiteMapDataSource's ability to hide nodes from users who lack proper authorization. Authorization is role-based and is enacted by including roles attributes in siteMapNode elements. Of course, you can use ASP.NET 2.0 Role Management service to define roles and map users to roles. Security trimming is disabled by default in XmlSiteMapProvider. You can enable it by including these statements in Web.config.

SiteMapPath Control

This control creates a navigation hierarchy what is sometimes referred to as Bread crumb navigation. The SiteMapPath control does not need a data source. All one needs is to drag and drop a SiteMap path control onto the page and you all have the results at your disposal. You can change the properties such as the depth of the hierarchy and styles.

No comments: