Web Site Navigation How to get around in an ASP.NET web application 1Web Site Navigation
Links HTML anchor – Text ASP.NET HyperLink control – Text – Can be manipulated in the code-behind Example: aspnet/navigation/links 2Web Site Navigation
URL Uniform Ressource Locator Absolute URL – – Protocol://host/ressource Relative URL – Relative to the current page – /file.txt File in current folder – /subfolder/file.txt File in subfolder –../file.txt File in parent folder 3Web Site Navigation
Default documents URLS may lead to a folder, not a file – The web server will look for a default document in the folder Web servers can be configured to handled a list of default documents like 1.Default.aspx 2.Index.htm 3.Index.html 4.Etc. 4Web Site Navigation
ASP.NET navigation controls ASP.NET includes a few navigation controls – Menu – TreeView – SiteMapPath (aka. Bread crumps) – Visual studio The controls uses a logical structure of the web site defined in the file web.sitemap Example: aspnet/navigation/sitemap 5Web Site Navigation
Web.sitemap XML file with the logical structure of the web site – Not much help from Visual Studio to create this file 6Web Site Navigation
Menu Control Menu sub-items a unfolded as you hover the mouse over an item Uses the web.sitemap through a DataSource control – May also use other data sources than web.sitemap Can be styled in many different ways – Using CSS 7Web Site Navigation
TreeView Control Sub-trees can be collapsed / expanded by clicking Uses the web.sitemap through a DataSource control – May also use other data sources than web.sitemap Can be styled in many different ways – Using CSS 8Web Site Navigation
SiteMapPath Also known ad bread crumps Typically shown at the top of each page to tell the user where in the web site’s structure. Uses the file web.sitemap directly – No DataSource control used Typically included in a master page … … 9Web Site Navigation
Programmatic Redirection A web form usually submits data back the itself. – Sometimes you might want to go to a different page Client-side redirects – The client is responsible for the redirect. – Requires extra request/response – Can redirect to any web site Server-side redirect – The server is responsible for the redirect – No extra request/response – Can only redirect to other pages in this web site 10Web Site Navigation
Client-side redirects Client does the redirect ASP.NET Response object – Response.Redirect(newUrl) HTTP response: 303 moved temporarily – Response.RedirectPermanent(newUrl) HTTP response: 301 moved permanent Search engines will stop looking for the page 11Web Site Navigation
Server-side redirects Server does the redirect URL in browser not changed – Browser does not know about the redirect ASP.NET – Server.Transfer(url); – Server.Transfer(url?parameterName:value) Get the parameter value using Request.QueryString(parameterName) 12Web Site Navigation
Further readings, etc. Imar Spaanjaars Beginning ASP.NET 4 in C# and VB, Wrox 2010 – Chapter 7 Navigation, page Bill Evjen Professional ASP.NET 4 in C# and VB, Wrox 2010 – Chapter 13 Site Navigation, page George Shepherd Microsoft ASP.NET 4 Step by Step, Microsoft Press 2010 – Chapter 11 Web Site Navigation, page W3Schools.com ASP.NET 2.0 – Navigation – Chris Peels How Do I Implements Site Navigation in ASP.NET (video) – navigation-in-aspnet, navigation-in-aspnet 13Web Site Navigation