Page 1 of 1

Custom navigation fails on localhost

Posted: Thu Nov 06, 2008 11:10 am
by bobr2k
Help! we have a customized navigation scriplet which runs fine on the server using a slash without the tilde such as:
<li><a href="/Basket.aspx">View Cart</a></li>
which shows on the status line when you hover over it as "http://www.storename.com/Basket.aspx" - everything works great.
However when it runs on the localhost it comes up "http://localhost/Basket.aspx" and does not run because the storename is missing.
If I add a tilde
<li><a href="~/Basket.aspx">View Cart</a></li>
the status line resolves as: http://localhost/storename/~/basket.aspx[/quote] which of course does not run. I've been scanning html tutorials and AC7 elements which uses both types of urls but I can't determine why this is failing or how to correct it. Does anyone have any other ideas? Is there a way to tell the site it is running from the server or from the localhost so it will resolve the url properly?

Re: Custom navigation fails on localhost

Posted: Thu Nov 06, 2008 11:16 am
by mazhar
Have you tried by removing the both ~/

Re: Custom navigation fails on localhost

Posted: Thu Nov 06, 2008 11:52 am
by bobr2k
mazhar wrote:Have you tried by removing the both ~/
Yes - when I remove both from the links I run into a problem in checkout so if a user tries to go to products while in checkout the url resolves to "http://www.storename.com/checkout/search.aspx" (the same thing occurs for contact us, etc.)

Re: Custom navigation fails on localhost

Posted: Thu Nov 06, 2008 12:44 pm
by bobr2k
I found this but I don't understand how to apply it:
Use this in any ASP.NET page to get the application path. For example, if you run this function in http://localhost/pathtest/test.aspx, the function will return http://localhost/pathtest/
From: Get Application Path [C# / ASP.NET] http://www.thejackol.com/2004/09/22/get ... -c-aspnet/
It sounds like it has something to do with resolving localhost from the master page. (Now if I just understood master pages) :oops: (still searching)

Re: Custom navigation fails on localhost

Posted: Fri Nov 07, 2008 9:41 pm
by AbleMods
You're confusing HTML link tags with ASP.NET link tags. The syntax is very different between them.

Code: Select all

<li><a href="~/Basket.aspx">View Cart</a></li>
is an HTML link tag, not ASP.Net.

If you want an HTML tag to render relative to the page that contains it, use "./"

So the correct syntax would be

Code: Select all

<li><a href="./Basket.aspx">View Cart</a></li>
If you want the URL to be absolute from the root of the site, you use "../"

So no matter where the page that contains the link is located,

Code: Select all

<a href="../Basket.aspx">
will always result in http://www.mysite.com/basket.aspx

Re: Custom navigation fails on localhost

Posted: Sat Nov 08, 2008 9:24 am
by bobr2k
Unfortunately Joe, I've tried both of those and they don't always work either.

Re: Custom navigation fails on localhost

Posted: Sat Nov 08, 2008 10:18 am
by AbleMods
What's the full URL of the page you want that link on?

Re: Custom navigation fails on localhost

Posted: Sat Nov 08, 2008 11:02 am
by bobr2k
SolunarServices wrote:What's the full URL of the page you want that link on?
When it's on the server http://www.webermeats.com when it's on local http://localhost/weberdev/
(I've think I've got that right :? ) ... It's not just one link but all navigation links in the header, including basket, contact us, awards, our history, etc. the way we are using it seems to work on the server but I seem to need an entirely different setup on the localhost and even then links sometimes fail when I come out of admin to the store or when I try to go from basket to one of the other pages, checkout gets stuck in the middle of the link and the link fails.

Re: Custom navigation fails on localhost

Posted: Sat Nov 08, 2008 1:23 pm
by AbleMods
Is this in an AC7 scriptlet or something you've built directly into an ASPX page?

Re: Custom navigation fails on localhost

Posted: Sat Nov 08, 2008 3:15 pm
by bobr2k
SolunarServices wrote:Is this in an AC7 scriptlet or something you've built directly into an ASPX page?
It's in a custom conlib -
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CommonNav.ascx.cs" Inherits="ConLib_Custom_CommonNav" %>
<ul id="<%= NavIdName %>" class="nav clearfix">
<li class="first"><a href="Search.aspx">Products</a> </li>
<li><a href="#">Processing</a>&nbsp;
<ul class="subnav">
<li><a href="/Assets/BeefOptions.pdf" target="_blank">Beef Processing</a></li>
<li><a href="/Assets/PorkOptions.pdf" target="_blank">Pork Processing</a></li>
<li><a href="/Assets/Venison.pdf" target="_blank">Venison Processing</a></li>
</ul>
</li>
<li><a href="/OurHistory.aspx">Our History</a>&nbsp; </li>
<li><a href="/Awards.aspx">Awards</a>&nbsp; </li>
<li><a href="/ContactUs.aspx">Contact Us</a>&nbsp; </li>
<li><a href="/Basket.aspx">View Cart</a>&nbsp; </li>
<li></li>
<li></li>
<li class="last"><a href="/Members/MyAccount.aspx">Account&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
<ul class="subnav">
<li><asp:HyperLink ID="LoginLogoutLink" runat="server" /></li>
<li><a href="/Members/MyAccount.aspx">My Account</a></li>
<li><a href="/Members/MyWishlist.aspx">My Wishlist</a></li>
<li><a href="/FindWishlist.aspx">Find Wishlist</a></li>
<asp:PlaceHolder ID="PlaceholderAdminLink" runat="server" Visible="false"><li><a href="/Admin/">Admin</a></li></asp:PlaceHolder>
</ul>
</li>
</ul>

Re: Custom navigation fails on localhost

Posted: Sat Nov 08, 2008 6:44 pm
by AbleMods
Let's practice on one link. Once we get it working, we'll fix the others.

Instead of this:

Code: Select all

<a href="Search.aspx">Products</a>
Try this:

Code: Select all

<asp:LinkButton ID="LinkButton1" runat="server" Text="Products" PostBackUrl="~/Search.aspx"></asp:LinkButton>
Let me know if that works.

Re: Custom navigation fails on localhost

Posted: Mon Nov 10, 2008 3:40 pm
by bobr2k
SolunarServices wrote:Let's practice on one link. Let me know if that works.
Looks to me like it's working. I can probably get the rest by following the same procedure. I just knew there was a way to get it to work. Thanks Joe! :mrgreen:

Re: Custom navigation fails on localhost

Posted: Mon Nov 10, 2008 4:10 pm
by AbleMods
You are most welcome.

If you use more Link Button controls on the same page, just be sure to change the ID value so that each control has a unique ID.

Something as simple as:
ID="LinkButton1"
ID="LinkButton2"
.
.
.

is completely fine. The ID is only used to reference the control through programming, so in your case it's not really all that critical.