Uploaded on

WebSite Navigation

WebSite Navigation

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
316
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
9
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. • Site Maps• Defining a Site Map• Site Map Rules• Binding a Page to Site Map• SiteMapPath Control• TreeView Control• Menu Control• URL Mapping and Routing
  • 2. ASP.NET includes a navigation model that makes it easy tolet users surf through your web applications.It consists of three components:• A way to define the navigational structure of your website.(XML SiteMap)• A convenient way to read the information in the site map fileand convert it to an object model (SiteMapDataSourcecontrol and the XmlSiteMapProvider)• A way to use the site map information to display the user’scurrent position and give the user the ability to easily movefrom one place to another (Navigation Controls)
  • 3. • The starting point in site map-based navigation is the XmlSiteMapProvider which retrieves site map information from an XML file.• The XmlSiteMapProvider looks for a file named Web.sitemap in the root of the virtual directory.• XmlSiteMapProvider extracts the site map data and create the corresponding SiteMap object.• SiteMap object is then made available to the SiteMapDataSource, which you place on every page that uses navigation.• The SiteMapDataSource provides the site map information to navigation controls, which are the final link in the chain.
  • 4. Before you can fill in the content in your site map file,you need to understand the rules that all ASP.NET sitemaps must follow.• Rule 1: Site Maps Begin with the <siteMap> Element• Rule 2: Each Page Is Represented by a <siteMapNode> Element• Rule 3: A <siteMapNode> Element Can Contain Other <siteMapNode> Elements• Rule 4: Every Site Map Begins with a Single <siteMapNode>• Rule 5: Duplicate URLs Are Not Allowed
  • 5. <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"><siteMapNode title="Home" description="Home" url="~/default.aspx"><siteMapNode title="Information" description="Learn about our company“> <siteMapNode title="About Us“ description="How RevoTech was founded“ url="~/aboutus.aspx" /> <siteMapNode title="Investing“ description="Financial reports and investor analysis“ url="~/financial.aspx" /></siteMapNode><siteMapNode title="Products" description="Learn about our products"> <siteMapNode title="RevoStock“ description="Investment software for stock charting“ url="~/product1.aspx" /> <siteMapNode title="RevoAnalyze“ description="Investment software for yield analysis“ url="~/product2.aspx" /></siteMapNode></siteMapNode></siteMap>
  • 6. You can create a site map using a text editor such asNotepad, or you can create it in Visual Studio byselecting Website ➤ Add New Item and then choosingthe Site Map option.Once you’ve defined the Web.sitemap file, you’re readyto use it in a page the next step is to add theSiteMapDataSource control to your page.The last step is to add controls that are linked to theSiteMapDataSource. These are the three navigationcontrols:• TreeView• Menu• SiteMapPath
  • 7. Website navigation works best when combined withanother ASP.NET feature—master pages.That’s because you’ll usually want to show the samenavigation controls on every page.The easiest way to do this is to create a master pagethat includes the SiteMapDataSource and the navigationcontrols.You can then reuse this template for every other page onyour site.
  • 8. The SiteMapPath provides breadcrumb navigation,which means it shows the user’s current location andallows the user to navigate up the hierarchy to a higherlevel using links.
  • 9. By breaking a single site map into separate files using thesiteMapFile attribute, like this:<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" ><siteMapNode title="Root" description="Root" url="~/default.aspx"><siteMapNode siteMapFile="Dealers.sitemap" /><siteMapNode siteMapFile="Employees.sitemap" /></siteMapNode></siteMap>
  • 10. The site map model is designed around a simpleprinciple: each entry has a separate URL.Although you can distinguish URLs by addingquery string arguments, in many websites there isone-to-one correspondence between web formsand site map entries.ASP.NET has two tools that may be able to helpyou:• URL Mapping• URL Routing
  • 11. In some situations, you might want to have several URLs lead tothe same page. This might be the case for a number ofreasons—maybe you want to implement your logic in one pageand use query string arguments but still provide shorter andeasier-to-remember URLs to your website users.You define URL mapping in the <urlMappings> section of theweb.config file. You supply two pieces of information—therequest URL (as the url attribute) and the new destination URL(mappedUrl).<configuration><system.web><urlMappings enabled="true"><add url="~/category.aspx"mappedUrl="~/default.aspx?category=default" /><add url="~/software.aspx"mappedUrl="~/default.aspx?category=software" /></urlMappings>...</system.web></configuration>
  • 12. Unlike URL mapping, URL routing doesn’t take placein the web.config file. Instead, it’s implemented usingcode. Typically, you’ll use the Application_Start()method in the global.asax file to register all the routesfor your application.To register a route, you use the RouteTable class fromthe System.Web.Routing namespace. It provides astatic property named Routes, which holds acollection of Route objects that are defined foryour application. Initially, this collection is empty, butyou can your custom routes by calling theMapPageRoute() method, which takes threearguments: routeName, routeUrl, physicalFile
  • 13. protected void Application_Start(object sender, EventArgs e){RouteTable.Routes.MapPageRoute("product-details","product/{productID}", "~/productInfo.aspx");RouteTable.Routes.MapPageRoute("products-in-category","products/category/{categoryID}", "~/products.aspx");}Here’s a URL that uses this route to request a product with theID FI_00345:http://localhost:[PortNumber]/Routing/product/FI_00345