Hiding Default / Index Page Name in URL Location Bar
Okay, so after a month's off-and-on search for answers to this, I think I've finally gotten my workaround working.
When you visit an url without defining a specific document, whatever server is serving the page is usually instructed to provide a default document, e.g. index.html or default.aspx. Nothing new here.
The problem creeps in when using an asp.net sitemap, which requires that the entire page path be enumerated, such as ~/Test/Default.aspx, in order for controls like the breadcrumb to "know" which page a visitor is on. When you click on links generated by these controls, you are taken to the full url (including the default page name). I want to hide the default page name.
My original thinking was to test Request.ServerVariables("SCRIPT_NAME") for the default page, and then redirect the browser to the truncated URL. Since any of the ASP Request.ServerVariables, as well as Request.Path, include the full path whether the request implicitly or explicitly names the default document, that's no help.
Instead, the only way to see what's in the browser's address bar is via client-side scripting, and the best part is: it only takes two lines of javascript code.
The only drawback to this method is that it has to update the location, which creates another GET to the server. However, the location.replace() does not create a new history entry, so this method is almost completely transparent to the visitor.
<code>
var testremove = location.href.toLowerCase().indexOf("default.aspx");
if (testremove != -1) {location.replace(location.href.substring(0,testremove))};
</code>
Of course, replace default.aspx with whatever your default document is called, or repeat this concept for additional default document names... Attached is the .JS file that you can just drop in to your page as well.
I hope this helps at least one person out there, because this would have saved me a small headache. I know it really doesn't matter if it shows the default name or not. I'm just a stickler for stupid details.