yahya kh
yahya kh

Reputation: 751

ASP.Net pages relative paths?

I have a website which i run localy and the path on the browser is

"http://localhost:3184/basel/index.aspx"

I have a menu which contains various hyperlinks and one of them is:

<a href="en/open-account/index.aspx"></a>
//This will evaluate to http://localhost:3184/basel/en/open-account/index.aspx.

The hyperlink will redirect me the page above, After that when i try to click the same link again on the menu, the path of the page is the following:

"http://localhost:3184/basel/en/open-account/en/open-account/index.aspx"

Why is it that the path have duplicated, i have been struggling for a while but can't seem to figure this out, Any solution ?

Upvotes: 0

Views: 647

Answers (3)

JayOnDotNet
JayOnDotNet

Reputation: 398

Use Page.ResolveUrl() method. If the relativeUrl have an absolute URL, the URL is returned unchanged. If the relativeUrl have contains a relative URL, that URL is changed to a relative URL that is correct for the current request path, so that the browser can resolve the URL

Upvotes: 0

user1105802
user1105802

Reputation:

What is in your code behind? If the A tag is being set dynamically (maybe something like this myHyperlink.NavigateURL += "en/open-account/index.aspx";) then each time the page is loaded the URL will have a new value appended to the end.

Maybe check the code behind to see if this URL is being manipulated there? If you've already done so, my apologies :)

Upvotes: 0

danludwig
danludwig

Reputation: 47375

Try this:

<a href="~/en/open-account/index.aspx" runat="server"></a>

Using the tilde creates an application-relative path.

Upvotes: 1

Related Questions